chore(shell): make everything bit faster

This commit is contained in:
2023-09-27 10:38:10 +03:00
parent 6f854ddbfd
commit a87b33b8c2
18 changed files with 159 additions and 109 deletions

View File

@@ -19,11 +19,11 @@ indent_size = 1
indent_size = 1
indent_style = tab
[{local/bin/*,**/*.sh,**/zshrc}]
[{local/bin/*,**/*.sh,**/zshrc,config/*}]
shell_variant = bash # --language-variant
binary_next_line = true
switch_case_indent = true # --case-indent
space_redirects = true
keep_padding = true
keep_padding = false
function_next_line = true # --func-next-line

View File

@@ -3,6 +3,9 @@
# Defaults
export DOTFILES="$HOME/.dotfiles"
export DOTFILES_SHARED_LOADED=""
# shellcheck source=scripts/shared.sh
source "$DOTFILES/scripts/shared.sh"
# Run x-load-configs in your terminal to reload the files.
function x-load-configs()

View File

@@ -3,6 +3,7 @@
# Defaults
export DOTFILES="$HOME/.dotfiles"
export DOTFILES_SHARED_LOADED=""
# shellcheck source=scripts/shared.sh
source "$DOTFILES/scripts/shared.sh"
@@ -30,38 +31,69 @@ function x-load-configs()
}
x-load-configs
export HISTFILE="$XDG_STATE_HOME"/zsh/history
autoload -U colors zsh/terminfo
colors
export ZSH_CUSTOM_COMPLETION_PATH="$XDG_CONFIG_HOME/zsh/completion"
x-dc "$ZSH_CUSTOM_COMPLETION_PATH"
# Add completion scripts to zsh path
FPATH="$ZSH_CUSTOM_COMPLETION_PATH:$FPATH"
autoload -Uz compinit
if type brew &> /dev/null; then
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"
FPATH="$HOMEBREW_PREFIX/share/zsh/site-functions:${FPATH}"
fi
compinit -d "$XDG_CACHE_HOME"/zsh/zcompdump-"$ZSH_VERSION"
# Try to load antigen, if present
ANTIGEN_ZSH_PATH="$XDG_BIN_HOME/antigen.zsh"
# shellcheck source=../../.local/bin/antigen.zsh
[[ -f "$ANTIGEN_ZSH_PATH" ]] && source "$ANTIGEN_ZSH_PATH"
# antigen is present
have antigen && {
antigen use oh-my-zsh
antigen use oh-my-zsh
# config/functions
x-default-antigen-bundles
export ZSH_TMUX_AUTOSTART=false
export ZSH_TMUX_CONFIG="$DOTFILES/config/tmux/tmux.conf"
export ZSH_TMUX_UNICODE=true
export ZSH_TMUX_AUTOQUIT=false
export ZSH_TMUX_DEFAULT_SESSION_NAME=main
antigen apply
}
export NVM_DIR="$XDG_CONFIG_HOME/nvm"
export NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME"/npm/npmrc
# z, the zsh version
export ZSHZ_DATA="$XDG_STATE_HOME/z"
antigen bundle z
# these should be always available
antigen bundle tmux
antigen bundle colored-man-pages
antigen bundle command-not-found
antigen bundle ssh-agent
antigen bundle jreese/zsh-titles
antigen bundle unixorn/autoupdate-antigen.zshplugin
antigen bundle zsh-users/zsh-completions
# prettier history search
antigen bundle zsh-history-substring-search
bindkey "${terminfo[kcuu1]}" history-substring-search-up
bindkey "${terminfo[kcud1]}" history-substring-search-down
bindkey -M vicmd 'k' history-substring-search-up
bindkey -M vicmd 'j' history-substring-search-down
# these should be available if there's need
have brew && antigen bundle brew
have php && antigen bundle php
have python && antigen bundle MichaelAquilina/zsh-autoswitch-virtualenv
# nvm is a strange beast
zstyle ':omz:plugins:nvm' autoload yes
antigen bundle nvm
# antigen bundle "$DOTFILES/config/zsh/plugins/nvm-auto-use"
# nice to have stuff
antigen bundle gcloud
# this needs to be the last item
antigen bundle zsh-users/zsh-syntax-highlighting
antigen apply
# shellcheck source=../config/fzf/fzf.zsh
[ -f "${DOTFILES}/config/fzf/fzf.zsh" ] \

View File

@@ -8,7 +8,7 @@ function x-set-php-aliases
{
have brew && {
local php_versions=()
while IFS="" read -r line; do php_versions+=("$line"); done < <(brew list | grep '^php')
while IFS="" read -r line; do php_versions+=("$line"); done < <(brew_installed | grep '^php')
php_error_reporting='-d error_reporting=22527'
@@ -58,6 +58,9 @@ fi
# Be nice
alias please="sudo "
# Color the grep output
alias grep='grep --color'
! have eza && alias ls='ls --color=auto'
have eza && {
alias ls='eza -h -s=type --git --icons --group-directories-first'
@@ -68,9 +71,12 @@ alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
# Colors for ls
alias ll="ls -l"
alias l="ls"
# cd to git root directory
alias cdgr='cd "$(git root)"'
# Shortcuts for listing
alias ll="ls -la"
alias l="ls -a"
# Prevent common typos
alias cd..="cd .."
@@ -79,12 +85,6 @@ alias sl="ls"
# List only directories
alias lsd="ls -lF | grep '^d'"
# Recursively delete `.pyc` files
alias rmpyc="find . -type f -name '*.pyc' -ls -delete"
# Recursively delete `.DS_Store` files
alias rmds="find . -type f -name '*.DS_Store' -ls -delete"
# IP addresses
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
alias localip="ipconfig getifaddr en1"
@@ -118,6 +118,10 @@ alias ta='tmux attach || tmux'
alias watchx='watch -dpbc'
# delete .DS_Store files
alias zapds='find . -name ".DS_Store" -print -delete'
# Recursively delete `.pyc` files
alias zappyc="find . -type f -name '*.pyc' -ls -delete"
# Run all zaps
alias zapall="zapds && zappyc"
# tail with follow flag on
alias t='tail -f'
# directory usage, return only the total

View File

@@ -23,11 +23,6 @@ have brew && eval "$(brew shellenv)"
path_append "/usr/local/bin"
path_append "$XDG_BIN_HOME"
# brew, https://brew.sh
have brew && {
have_brew python && path_append "$(brew --prefix python)/bin"
}
source "$DOTFILES/config/exports-shell"
source "$DOTFILES/config/exports-apps"

View File

@@ -3,6 +3,7 @@
# shellcheck enable=external-sources
# shellcheck disable=1091,2139
# vim: filetype=zsh
export DOTFILES="$HOME/.dotfiles"
source "$DOTFILES/scripts/shared.sh"
@@ -17,10 +18,8 @@ export ANTIGEN_PLUGIN_RECEIPT_F=".local/share/antigen/antigen_plugin_lastupdate"
export ANSIBLE_HOME="$XDG_CONFIG_HOME/ansible"
export ANSIBLE_CONFIG="$XDG_CONFIG_HOME/ansible.cfg"
export ANSIBLE_GALAXY_CACHE_DIR="$XDG_CACHE_HOME/ansible/galaxy_cache"
have ansible && {
x-dc "$ANSIBLE_HOME"
x-dc "$ANSIBLE_GALAXY_CACHE_DIR"
}
x-dc "$ANSIBLE_HOME"
x-dc "$ANSIBLE_GALAXY_CACHE_DIR"
export ANDROID_HOME="$XDG_DATA_HOME/android"
@@ -29,29 +28,18 @@ export HOMEBREW_NO_ENV_HINTS=true
# composer, https://getcomposer.org/
export COMPOSER_HOME="$XDG_STATE_HOME/composer"
export COMPOSER_BIN="$COMPOSER_HOME/vendor/bin"
have composer && {
export PATH="$COMPOSER_BIN:$PATH"
}
path_append "$COMPOSER_BIN"
# docker, https://docs.docker.com/engine/reference/commandline/cli/
export DOCKER_CONFIG="$XDG_CONFIG_HOME/docker"
have docker && {
x-dc "$DOCKER_CONFIG"
# Docker: Disable snyk ad
export DOCKER_SCAN_SUGGEST=false
}
x-dc "$DOCKER_CONFIG"
# Docker: Disable snyk ad
export DOCKER_SCAN_SUGGEST=false
# ffmpeg
export FFMPEG_DATADIR="$XDG_CONFIG_HOME/ffmpeg"
have ffmpeg && x-dc "$FFMPEG_DATADIR"
# gcloud
have gcloud && {
GCLOUD_LOC=$(gcloud info --format="value(installation.sdk_root)" --quiet)
[[ -f "$GCLOUD_LOC/path.zsh.inc" ]] && builtin source "$GCLOUD_LOC/path.zsh.inc"
[[ -f "$GCLOUD_LOC/completion.zsh.inc" ]] && builtin source "$GCLOUD_LOC/completion.zsh.inc"
}
# GnuPG
export GNUPGHOME="$XDG_DATA_HOME/gnupg"
@@ -71,17 +59,7 @@ have irssi && {
export NBRC_PATH="$XDG_CONFIG_HOME/nbrc"
export NB_DIR="$XDG_STATE_HOME/nb"
# nvm, the node version manager
export NVM_LAZY_LOAD=true
export NVM_COMPLETION=true
export NVM_AUTO_USE=true
export NVM_DIR="$XDG_CONFIG_HOME/nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
export NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME"/npm/npmrc
# Add npm packages to path
# NPM: Add npm packages to path
have node && {
NVM_NODE_BIN_DIR="$(dirname "$(which node)")"
path_append "$NVM_NODE_BIN_DIR"
@@ -100,8 +78,7 @@ have op && {
export WORKON_HOME="$XDG_DATA_HOME/virtualenvs"
export PYENV_ROOT="$XDG_STATE_HOME/pyenv"
have pyenv && {
path_append "$(pyenv root)/shims"
path_append "$PYENV_ROOT/bin"
path_append "$PYENV_ROOT/shims"
eval "$(pyenv init -)"
}
@@ -115,7 +92,7 @@ export BUNDLE_USER_CACHE="$XDG_CACHE_HOME"/bundle
export BUNDLE_USER_PLUGIN="$XDG_DATA_HOME"/bundle
export RBENV_ROOT="$XDG_STATE_HOME/rbenv"
x-dc "$RBENV_ROOT"
have gem && path_append "$(gem environment gemdir)/bin"
have gem && path_append "${GEM_HOME}/bin"
have rbenv && eval "$(rbenv init - zsh)"
# Rust / cargo
@@ -139,10 +116,6 @@ export TMUX_CONF="$XDG_CONFIG_HOME/tmux/tmux.conf"
export WAKATIME_HOME="$XDG_STATE_HOME/wakatime"
x-dc "$WAKATIME_HOME"
# z, https://github.com/rupa/z
export _Z_DATA="$XDG_STATE_HOME/z"
[[ -f "$XDG_BIN_HOME/z/z.sh" ]] && source "$XDG_BIN_HOME/z/z.sh"
# Misc
export BAT_THEME="ansi"
export CHEAT_USE_FZF=true

View File

@@ -2,6 +2,7 @@
# shellcheck shell=bash
# shellcheck disable=1091,2046
# vim: filetype=zsh
export DOTFILES="$HOME/.dotfiles"
source "$DOTFILES/scripts/shared.sh"
@@ -23,9 +24,16 @@ export HISTIGNORE="ls:cd:cd -:pwd:exit:date:* --help"
# And include the parameter for ZSH
export HISTORY_IGNORE="(ls|cd|cd -|pwd|exit|date|* --help)"
# Less history location
export LESSHISTFILE="$XDG_STATE_HOME"/less/history
# Highlight section titles in manual pages
export LESS_TERMCAP_md="$ORANGE"
# zsh autoloaded terminfo
export TERMINFO="$XDG_DATA_HOME"/terminfo
export TERMINFO_DIRS="$XDG_DATA_HOME"/terminfo:/usr/share/terminfo
# Dont clear the screen after quitting a manual page
export MANPAGER="less -X"
@@ -46,6 +54,10 @@ have dircolors && eval $(dircolors "$XDG_CONFIG_HOME/dircolors")
# If we are using zsh, color our dir lists and such
if [ "$SHELL" = "$(which zsh)" ]; then
autoload -U colors zsh/terminfo compinit
colors
compinit -d "$XDG_CACHE_HOME"/zsh/zcompdump-"$ZSH_VERSION"
x-dc "$XDG_CACHE_HOME/zsh"
x-dc "$XDG_STATE_HOME/zsh"
export HISTFILE="$XDG_STATE_HOME/zsh/history"

View File

@@ -57,31 +57,3 @@ scheduler()
sleep 60
done
}
# Defines default antigen bundles
x-default-antigen-bundles()
{
export ZSH_TMUX_AUTOSTART=false
export ZSH_TMUX_CONFIG="$DOTFILES/config/tmux/tmux.conf"
export ZSH_TMUX_UNICODE=true
export ZSH_TMUX_AUTOQUIT=false
export ZSH_TMUX_DEFAULT_SESSION_NAME=main
# these should be always available
antigen bundle tmux
antigen bundle colored-man-pages
antigen bundle command-not-found
antigen bundle ssh-agent
antigen bundle jreese/zsh-titles
antigen bundle unixorn/autoupdate-antigen.zshplugin
antigen bundle zsh-users/zsh-completions
antigen bundle zsh-users/zsh-syntax-highlighting
# these should be available if there's need
have brew && antigen bundle brew
# have nvm && antigen bundle nvm
have nvm && antigen bundle "$DOTFILES/config/zsh/plugins/nvm-auto-use"
have php && antigen bundle php
have python && antigen bundle MichaelAquilina/zsh-autoswitch-virtualenv
have rvm && antigen bundle unixorn/rvm-plugin
}

View File

@@ -18,6 +18,7 @@ SCRIPT=$(basename "$0")
VERSION_NVM="v0.39.5"
export DOTFILES_SHARED_LOADED=""
# shellcheck source=./../../scripts/shared.sh
source "$SHARED_SCRIPT"

View File

@@ -2,6 +2,7 @@
# Install cargo/rust packages.
#
# shellcheck source=shared.sh
DOTFILES_SHARED_LOADED=""
source "$HOME/.dotfiles/scripts/shared.sh"
! have cargo && {

View File

@@ -1,9 +1,10 @@
#!/usr/bin/env bash
# shellcheck disable=SC2231,SC2034,SC2181,SC2068
# shellcheck source=shared.sh
DOTFILES_SHARED_LOADED=""
source "$HOME/.dotfiles/scripts/shared.sh"
PBB_REQUIRED_TOOLS=(basename git mkdir cheat ls grep head awk cp echo rm)
PBB_REQUIRED_TOOLS=(git cheat)
for t in ${PBB_REQUIRED_TOOLS[@]}; do
! have "$t" && echo "(!) $t is missing, can't continue..." && exit 1
done

View File

@@ -1,9 +1,10 @@
#!/usr/bin/env bash
# shellcheck disable=SC2231,SC2034,SC2181,SC2068
# shellcheck source=shared.sh
DOTFILES_SHARED_LOADED=""
source "$HOME/.dotfiles/scripts/shared.sh"
TLDR_REQUIRED_TOOLS=(basename git mkdir cheat ls grep head awk cp echo rm)
TLDR_REQUIRED_TOOLS=(git cheat)
for t in ${TLDR_REQUIRED_TOOLS[@]}; do
! have "$t" && echo "(!) $t is missing, can't continue..." && exit 1
done

View File

@@ -4,6 +4,8 @@
# shellcheck source="shared.sh"
source "$HOME/.dotfiles/scripts/shared.sh"
msg_run "Installing gh (GitHub Client) extensions"
! have gh \
&& msg_err "gh (GitHub Client) could not be found, please install it first" \
&& exit 0
@@ -28,15 +30,13 @@ extensions=(
rsese/gh-actions-status
)
msg "Starting to install GitHub CLI extensions..."
for ext in "${extensions[@]}"; do
# Trim spaces
ext=${ext// /}
# Skip comments
if [[ ${ext:0:1} == "#" ]]; then continue; fi
msg_run "Installing $ext"
msg_nested "Installing $ext"
gh extensions install "$ext"
echo ""
done

View File

@@ -6,7 +6,7 @@
# shellcheck source=shared.sh
source "$HOME/.dotfiles/scripts/shared.sh"
msg "Installing git-crypt"
msg_run "Installing git-crypt"
! have git-crypt && {

View File

@@ -4,6 +4,8 @@
# shellcheck source=shared.sh
source "$HOME/.dotfiles/scripts/shared.sh"
msg_run "Installing go packages"
! have go && msg "go hasn't been installed yet." && exit 0
packages=(
@@ -33,16 +35,17 @@ for pkg in "${packages[@]}"; do
# Skip comments
if [[ ${pkg:0:1} == "#" ]]; then continue; fi
msg_run "Installing go package:" "$pkg"
msg_nested "Installing go package: $pkg"
go install "$pkg"
echo ""
done
msg "Installing completions for selected packages"
msg_run "Installing completions for selected packages"
have git-profile && {
git-profile completion zsh > "$ZSH_CUSTOM_COMPLETION_PATH/_git-profile" \
&& msg_yay "Installed completions for git-profile"
&& msg_ok "Installed completions for git-profile"
}
echo ""
msg_ok "Done"

View File

@@ -8,6 +8,11 @@
[ "$(uname)" != "Darwin" ] && echo "Not a macOS system" && exit 0
# shellcheck source=shared.sh
source "$HOME/.dotfiles/scripts/shared.sh"
msg_run "Starting to set macOS defaults, these require sudo privileges:"
# Ask for the administrator password upfront
sudo -v
@@ -19,6 +24,8 @@ while true; do
kill -0 "$$" || exit
done 2> /dev/null &
msg_nested "Change user shell to zsh if it is available and not the current"
# Change user shell to zsh if not that already.
if hash zsh 2> /dev/null; then
[[ "$SHELL" != $(which zsh) ]] && chsh -s "$(which zsh)"
@@ -28,6 +35,8 @@ fi
# General UI/UX #
###############################################################################
msg_nested "Setting General UI/UX settings"
# Disable the sound effects on boot
sudo nvram SystemAudioVolume=" "
@@ -80,6 +89,8 @@ defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
# SSD-specific tweaks #
###############################################################################
msg_nested "Setting SSD-specific tweaks"
# Disable hibernation (speeds up entering sleep mode)
sudo pmset -a hibernatemode 0
@@ -90,6 +101,8 @@ sudo pmset -a sms 0
# Trackpad, mouse, keyboard, Bluetooth accessories, and input #
###############################################################################
msg_nested "Settings for Trackpad, mouse, keyboard, Bluetooth accessories, and input"
# Increase sound quality for Bluetooth headphones/headsets
defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Max (editable)" 80
defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Min (editable)" 80
@@ -124,6 +137,8 @@ defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
# Screen #
###############################################################################
msg_nested "Settings for Screen"
# Require password immediately after sleep or screen saver begins
defaults write com.apple.screensaver askForPassword -int 1
defaults write com.apple.screensaver askForPasswordDelay -int 0
@@ -132,6 +147,8 @@ defaults write com.apple.screensaver askForPasswordDelay -int 0
# Finder #
###############################################################################
msg_nested "Settings for Finder"
# Set Desktop as the default location for new Finder windows
# For other paths, use `PfLo` and `file:///full/path/here/`
defaults write com.apple.finder NewWindowTarget -string "PfDe"
@@ -190,6 +207,8 @@ defaults write com.apple.finder FXInfoPanesExpanded -dict \
# Screenshots #
###############################################################################
msg_nested "Settings for Screenshots"
# Set default screenshot location
mkdir -p "$HOME/Documents/Screenshots"
defaults write com.apple.screencapture "location" -string "$HOME/Documents/Screenshots"
@@ -204,6 +223,8 @@ defaults write com.apple.screencapture "name" -string "screenshot"
# Dock, Dashboard, and hot corners #
###############################################################################
msg_nested "Settings for Dock, Dashboard, and hot corners"
# Prevent applications from bouncing in Dock
defaults write com.apple.dock no-bouncing -bool true
@@ -234,6 +255,8 @@ defaults write com.apple.dock showhidden -bool true
# Safari & WebKit #
###############################################################################
msg_nested "Settings for Safari & WebKit"
# Enable Safaris debug menu
defaults write com.apple.Safari IncludeInternalDebugMenu -bool true
@@ -258,6 +281,8 @@ defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true
# Activity Monitor #
###############################################################################
msg_nested "Settings for ActivityMonitor"
# Show the main window when launching Activity Monitor
defaults write com.apple.ActivityMonitor OpenMainWindow -bool true
@@ -275,6 +300,8 @@ defaults write com.apple.ActivityMonitor SortDirection -int 0
# Address Book, Dashboard, iCal, TextEdit, and Disk Utility #
###############################################################################
msg_nested "Settings for Address Book, Dashboard, iCal, TextEdit, and Disk Utility"
# Use plain text mode for new TextEdit documents
defaults write com.apple.TextEdit RichText -int 0
@@ -286,6 +313,8 @@ defaults write com.apple.TextEdit PlainTextEncodingForWrite -int 4
# Messages #
###############################################################################
msg_nested "Settings for Messages"
# Disable smart quotes as its annoying for messages that contain code
defaults write com.apple.messageshelper.MessageController \
SOInputLineSettings \
@@ -298,6 +327,8 @@ defaults write com.apple.messageshelper.MessageController \
-dict-add "continuousSpellCheckingEnabled" \
-bool false
msg_nested "Restarting applications to apply changes"
###############################################################################
# Kill affected applications #
###############################################################################
@@ -307,4 +338,5 @@ for app in "Activity Monitor" "Address Book" "Calendar" "Contacts" "cfprefsd" \
"Terminal" "Transmission" "Twitter" "iCal"; do
killall "${app}" > /dev/null 2>&1
done
echo "Done. Note that some of these changes require a logout/restart to take effect."
msg_yay "Done. Note that some of these changes require a logout/restart to take effect."

View File

@@ -6,6 +6,10 @@
# Helper env variables. Use like this: VERBOSE=1 ./script.sh
: "${VERBOSE:=0}"
# If this file has already been loaded, no need to reload it.
[ "$DOTFILES_SHARED_LOADED" = "yes" ] && return
export DOTFILES_SHARED_LOADED="yes"
# -- Colors -- #
CLR_RED="\033[1;31m"
CLR_YELLOW="\033[1;33m"
@@ -201,7 +205,7 @@ function menu_usage()
if command -v bkt >&/dev/null; then
bkt()
{
command bkt "$@"
command bkt --cache-dir="$XDG_CACHE_HOME/bkt" "$@"
}
else
# If bkt isn't installed skip its arguments and just execute directly.
@@ -213,7 +217,16 @@ else
}
fi
# shorthand for checking if the system has the bin in path.
# shorthand for checking if the system has the bin in path,
# this version does not use caching
# usage: have_command php && php -v
function have_command
{
command -v "$1" >&/dev/null
}
# shorthand for checking if the system has the bin in path,
# this version uses caching
# usage: have php && php -v
function have
{
@@ -357,3 +370,9 @@ ask()
fi
done
}
# Check if a file contains non-ascii characters
nonascii()
{
LC_ALL=C grep -n '[^[:print:][:space:]]' "${@}"
}

View File

@@ -1,2 +1,3 @@
ensurepath
openapi-python-client
libtmux