zsh: possible new feature: remove invalid aliases
This commit is contained in:
parent
c65266da35
commit
45c511e337
1 changed files with 49 additions and 15 deletions
64
.zshrc
64
.zshrc
|
@ -49,7 +49,9 @@
|
||||||
{
|
{
|
||||||
## Short hand programs (ex: sc = shellcheck) >>>
|
## Short hand programs (ex: sc = shellcheck) >>>
|
||||||
# use nvim rather than vim if the command exists
|
# 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 \
|
alias \
|
||||||
vv="$EDITOR" \
|
vv="$EDITOR" \
|
||||||
|
@ -60,8 +62,8 @@
|
||||||
alias :q='exit' \
|
alias :q='exit' \
|
||||||
q='exit' \
|
q='exit' \
|
||||||
|
|
||||||
alias vim=nvim
|
|
||||||
alias sc=shellcheck
|
alias sc=shellcheck
|
||||||
|
|
||||||
# rmdir is long
|
# rmdir is long
|
||||||
alias \
|
alias \
|
||||||
rmd='rmdir' \
|
rmd='rmdir' \
|
||||||
|
@ -106,7 +108,7 @@
|
||||||
alias sdn='shutdown now'
|
alias sdn='shutdown now'
|
||||||
|
|
||||||
# open a new session called 0, but if there is already a session called 0, connect to it
|
# 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.
|
# List available X displays. Useful for finding what display to export when connected over ssh.
|
||||||
alias lsx='ls /tmp/.X11-unix | tr "X" ":"'
|
alias lsx='ls /tmp/.X11-unix | tr "X" ":"'
|
||||||
|
@ -136,7 +138,7 @@
|
||||||
alias cpv="rsync -ah --info=progress2"
|
alias cpv="rsync -ah --info=progress2"
|
||||||
|
|
||||||
# lists all open ports, along with some other info
|
# 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
|
# 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"
|
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
|
# optionally source an external alias file
|
||||||
[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/aliasrc" ] && source "${XDG_CONFIG_HOME:-$HOME/.config}/shell/aliasrc"
|
[ -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 >>>
|
### Functions >>>
|
||||||
|
@ -179,7 +197,7 @@
|
||||||
fi
|
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
|
# can take an `fd` command
|
||||||
# requires that `fzy` is installed
|
# requires that `fzy` is installed
|
||||||
cdf() {
|
cdf() {
|
||||||
|
@ -275,12 +293,28 @@
|
||||||
echo "$FILEPATH" | grep -o 'site.*' | sed 's+^site+https://blakenorth.net+g'
|
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
|
# for sending error messages from functions and whatnot
|
||||||
error() {
|
error() {
|
||||||
ERROR_CODE="$?"
|
ERROR_CODE="$?"
|
||||||
>&2 echo "An error occurred within a function in the .zshrc on line number ${1}"
|
>&2 echo "An error occurred within a function in the .zshrc on line number ${1}"
|
||||||
return $ERROR_CODE
|
return $ERROR_CODE
|
||||||
}
|
}
|
||||||
|
|
||||||
# prcolors(): Display all colors in a few different ways >>>
|
# prcolors(): Display all colors in a few different ways >>>
|
||||||
# TODO: change this to make it not just a few scripts smashed together
|
# TODO: change this to make it not just a few scripts smashed together
|
||||||
|
@ -301,7 +335,7 @@
|
||||||
for bgc in {40..47}; do
|
for bgc in {40..47}; do
|
||||||
fgc=${fgc#37} # white
|
fgc=${fgc#37} # white
|
||||||
bgc=${bgc#40} # black
|
bgc=${bgc#40} # black
|
||||||
|
|
||||||
vals="${fgc:+$fgc;}${bgc}"
|
vals="${fgc:+$fgc;}${bgc}"
|
||||||
vals=${vals%%;}
|
vals=${vals%%;}
|
||||||
|
|
||||||
|
@ -316,14 +350,14 @@
|
||||||
elif [ $1 -eq '2' ];then
|
elif [ $1 -eq '2' ];then
|
||||||
# from base16shell >>>
|
# from base16shell >>>
|
||||||
ansi_mappings=(
|
ansi_mappings=(
|
||||||
Red Green
|
Red Green
|
||||||
Yellow Blue
|
Yellow Blue
|
||||||
Magenta Cyan
|
Magenta Cyan
|
||||||
White Black
|
White Black
|
||||||
Bright_Red Bright_Green
|
Bright_Red Bright_Green
|
||||||
Bright_Yellow Bright_Blue
|
Bright_Yellow Bright_Blue
|
||||||
Bright_Magenta Bright_Cyan
|
Bright_Magenta Bright_Cyan
|
||||||
Bright_White Bright_Black
|
Bright_White Bright_Black
|
||||||
)
|
)
|
||||||
colors=(
|
colors=(
|
||||||
base00 base08
|
base00 base08
|
||||||
|
@ -345,7 +379,7 @@
|
||||||
non_padded_value=$((10#$padded_value))
|
non_padded_value=$((10#$padded_value))
|
||||||
base16_color_name=${colors[$non_padded_value]}
|
base16_color_name=${colors[$non_padded_value]}
|
||||||
current_color_label=${current_color:-unknown}
|
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___________________________")
|
block=$(printf "\x1b[48;5;${non_padded_value}m___________________________")
|
||||||
foreground=$(printf "\x1b[38;5;${non_padded_value}m$color_variable")
|
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
|
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
|
mkdir -p "$1" || error $LINENO
|
||||||
cd "$1" || error $LINENO
|
cd "$1" || error $LINENO
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
random-mac() {
|
random-mac() {
|
||||||
interfaces=(enp5s0 wlp4s0)
|
interfaces=(enp5s0 wlp4s0)
|
||||||
|
@ -483,7 +517,7 @@
|
||||||
## Themes
|
## Themes
|
||||||
# terminal colors
|
# terminal colors
|
||||||
if [[ -f ~/.config/shell/colors.sh ]];then
|
if [[ -f ~/.config/shell/colors.sh ]];then
|
||||||
source ~/.config/shell/colors.sh
|
source ~/.config/shell/colors.sh
|
||||||
else
|
else
|
||||||
zinit snippet 'https://github.com/chriskempson/base16-shell/blob/master/scripts/base16-onedark.sh' # onedark shell colors
|
zinit snippet 'https://github.com/chriskempson/base16-shell/blob/master/scripts/base16-onedark.sh' # onedark shell colors
|
||||||
fi
|
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)
|
# This section is (mostly) From manjaro's "manjaro-zsh-config" (/usr/share/zsh/manjaro-zsh-config)
|
||||||
|
|
||||||
[ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history"
|
[ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history"
|
||||||
|
@ -662,7 +696,7 @@ function mzc_termsupport_preexec {
|
||||||
# split command into array of arguments
|
# split command into array of arguments
|
||||||
local -a cmdargs
|
local -a cmdargs
|
||||||
cmdargs=("${(z)2}") # " <- syntax highlighting fix
|
cmdargs=("${(z)2}") # " <- syntax highlighting fix
|
||||||
|
|
||||||
# if running fg, extract the command from the job description
|
# if running fg, extract the command from the job description
|
||||||
if [[ "${cmdargs[1]}" = fg ]]; then
|
if [[ "${cmdargs[1]}" = fg ]]; then
|
||||||
# get the job id from the first argument passed to the fg command
|
# get the job id from the first argument passed to the fg command
|
||||||
|
|
Loading…
Add table
Reference in a new issue