diff --git a/.zshrc b/.zshrc index b2ccf2a..482d2a4 100644 --- a/.zshrc +++ b/.zshrc @@ -49,7 +49,9 @@ { ## Short hand programs (ex: sc = shellcheck) >>> # use nvim rather than vim if the command exists - [ -x "$(command -v nvim)" ] && alias vim='nvim' vimdiff='nvim -d' + alias \ + vim='nvim' \ + vimdiff='nvim -d' alias \ vv="$EDITOR" \ @@ -60,8 +62,8 @@ alias :q='exit' \ q='exit' \ - alias vim=nvim alias sc=shellcheck + # rmdir is long alias \ rmd='rmdir' \ @@ -106,7 +108,7 @@ alias sdn='shutdown now' # open a new session called 0, but if there is already a session called 0, connect to it - alias tm='tmux new -As0' + alias tm='tmux new -As0' # List available X displays. Useful for finding what display to export when connected over ssh. alias lsx='ls /tmp/.X11-unix | tr "X" ":"' @@ -136,7 +138,7 @@ alias cpv="rsync -ah --info=progress2" # lists all open ports, along with some other info - alias ls-ports='netstat -tulpn' + alias ls-ports='netstat -tulpn' # list all disks and their mount points alias mnt="mount | awk -F' ' '{ printf \"%s\t%s\n\",\$1,\$3; }' | column -t | grep -E '^/dev/' | sort" @@ -164,6 +166,22 @@ # <<< # optionally source an external alias file [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/aliasrc" ] && source "${XDG_CONFIG_HOME:-$HOME/.config}/shell/aliasrc" + + # # TODO: remove all aliases that refrence programs which do not exist >>> + # validate_alias() { + # # check if the alias points to an alias + # if alias "$(alias lsd | grep -Po "(?<=').*(?=')")"; then + # : + # else + # # see if the thing the alias points to is an executable + # test -x "$(command -V "$1" | grep -Po "(?<=$1 is )/.*$")" + # fi + # } + # for ALIAS in $(alias | cut -d = -f 1);do + # validate_alias "$ALIAS" && + # unalias "$ALIAS" && + # echo "alias $ALIAS was removed" + # done # <<< } # <<< ### Functions >>> @@ -179,7 +197,7 @@ fi } - # cd file: cd to the containing dir of a file, given part of its name + # cd file: cd to the containing dir of a file or folder, given part of its name # can take an `fd` command # requires that `fzy` is installed cdf() { @@ -275,12 +293,28 @@ echo "$FILEPATH" | grep -o 'site.*' | sed 's+^site+https://blakenorth.net+g' } + # Opens a subshell in each of the directories below the one you're in, so + # you can execute commands in them + # If I use this enough, I may make something that can do more + # Ideas for what it could do in the future: + # - somehow record typed commands so they can be automatically repeated + # - maybe get the length of the histfile before and after, executing the + # last X number of commands + # - Maybe just add an argument that takes a command and executes it in all dirs + # (although that wouldn't be as good as recording actions bc it's easy to do + # that by just writing a for loop) + foreachdir() { + for DIR in *; do + (cd "$DIR" && zsh) + done + } + # for sending error messages from functions and whatnot error() { ERROR_CODE="$?" >&2 echo "An error occurred within a function in the .zshrc on line number ${1}" return $ERROR_CODE - } + } # prcolors(): Display all colors in a few different ways >>> # TODO: change this to make it not just a few scripts smashed together @@ -301,7 +335,7 @@ for bgc in {40..47}; do fgc=${fgc#37} # white bgc=${bgc#40} # black - + vals="${fgc:+$fgc;}${bgc}" vals=${vals%%;} @@ -316,14 +350,14 @@ elif [ $1 -eq '2' ];then # from base16shell >>> ansi_mappings=( - Red Green + Red Green Yellow Blue Magenta Cyan White Black - Bright_Red Bright_Green + Bright_Red Bright_Green Bright_Yellow Bright_Blue Bright_Magenta Bright_Cyan - Bright_White Bright_Black + Bright_White Bright_Black ) colors=( base00 base08 @@ -345,7 +379,7 @@ non_padded_value=$((10#$padded_value)) base16_color_name=${colors[$non_padded_value]} current_color_label=${current_color:-unknown} - ansi_label=${ansi_mappings[$non_padded_value]} + ansi_label=${ansi_mappings[$non_padded_value]} block=$(printf "\x1b[48;5;${non_padded_value}m___________________________") foreground=$(printf "\x1b[38;5;${non_padded_value}m$color_variable") printf "%s %s %s %-30s %s\x1b[0m\n" $foreground $base16_color_name $current_color_label ${ansi_label:-""} $block @@ -377,7 +411,7 @@ mkdir -p "$1" || error $LINENO cd "$1" || error $LINENO } - + # shellcheck disable=SC2086 random-mac() { interfaces=(enp5s0 wlp4s0) @@ -483,7 +517,7 @@ ## Themes # terminal colors if [[ -f ~/.config/shell/colors.sh ]];then - source ~/.config/shell/colors.sh + source ~/.config/shell/colors.sh else zinit snippet 'https://github.com/chriskempson/base16-shell/blob/master/scripts/base16-onedark.sh' # onedark shell colors fi @@ -499,7 +533,7 @@ # <<< } # <<< -### General ZSH configuration >>> +### General ZSH configuration >>> # This section is (mostly) From manjaro's "manjaro-zsh-config" (/usr/share/zsh/manjaro-zsh-config) [ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history" @@ -662,7 +696,7 @@ function mzc_termsupport_preexec { # split command into array of arguments local -a cmdargs cmdargs=("${(z)2}") # " <- syntax highlighting fix - + # if running fg, extract the command from the job description if [[ "${cmdargs[1]}" = fg ]]; then # get the job id from the first argument passed to the fg command