config/shell: improve edbin & loca

This commit is contained in:
xeruf 2021-10-31 19:28:46 +01:00
parent 1fa210b99b
commit 58ef3cca99
3 changed files with 16 additions and 7 deletions

View File

@ -45,7 +45,7 @@ alias uloc='noglob sudo updatedb && loci'
locei() { locate --all --basename "\\$1" "$@" | fselect } locei() { locate --all --basename "\\$1" "$@" | fselect }
alias loce='noglob locei' alias loce='noglob locei'
# locate all # locate all
alias loca='noglob sudo updatedb --prunenames "" /var/lib/mlocate/all.db && loci --database ""' alias loca='noglob sudo updatedb --prunenames "" -o /var/lib/mlocate/all.db && loci --database /var/lib/mlocate/all.db'
# ZOXIDE # ZOXIDE
alias c=z alias c=z
@ -57,7 +57,7 @@ d() {
# If not select with fzf, using locate to find extra options # If not select with fzf, using locate to find extra options
cd "$(if test -n "$query" && expr "$(echo "$query" | head -1 | cut -d' ' -f1)" \> 20 \& $(echo "$query" | sed 'N;s|/.* \([0-9]\)|> 10 * \1|;q' | sed 's| */.*||') >/dev/null #2>&1 cd "$(if test -n "$query" && expr "$(echo "$query" | head -1 | cut -d' ' -f1)" \> 20 \& $(echo "$query" | sed 'N;s|/.* \([0-9]\)|> 10 * \1|;q' | sed 's| */.*||') >/dev/null #2>&1
then echo "$query" | head -1 then echo "$query" | head -1
else echo "$query"; locz "$@" else test -n "$query" && echo "$query"; locz "$@"
fi | zfz)" fi | zfz)"
} }
di() { di() {

View File

@ -62,6 +62,7 @@ pathadd() {
alias rs="reset && exec $SHELL" alias rs="reset && exec $SHELL"
alias hist='print -z $(history | tac | fzf --tiebreak=index --bind='"'"'del:execute(sed "\;$(echo {4..})$d" -i.bak $HISTFILE)'"'"' | sed "s|^ \+||" | cut -d" " -f5-)' alias hist='print -z $(history | tac | fzf --tiebreak=index --bind='"'"'del:execute(sed "\;$(echo {4..})$d" -i.bak $HISTFILE)'"'"' | sed "s|^ \+||" | cut -d" " -f5-)'
# Edit shell config files
CONFIG_SHELL_FUNCTIONS="${BASH_SOURCE[0]:-${(%):-%x}}" CONFIG_SHELL_FUNCTIONS="${BASH_SOURCE[0]:-${(%):-%x}}"
edshell() { edshell() {
case $1 in case $1 in
@ -69,15 +70,24 @@ edshell() {
(zsh) file="$CONFIG_ZSH/.zshrc";; (zsh) file="$CONFIG_ZSH/.zshrc";;
(prof*) file="$HOME/.zprofile";; (prof*) file="$HOME/.zprofile";;
(-f) grepfile="$(grep --recursive "\(^$2()\|alias $2=\)" $CONFIG_SHELLS -n -m 1)" (-f) grepfile="$(grep --recursive "\(^$2()\|alias $2=\)" $CONFIG_SHELLS -n -m 1)"
file=$(echo "$grepfile" | cut -d':' -f1) file="$(echo "$grepfile" | cut -d':' -f1)"
line=$(echo "$grepfile" | cut -d':' -f2);; line="$(echo "$grepfile" | cut -d':' -f2)";;
(*) file="$(find $CONFIG_SHELLS -name "$1*" | head -1 | grep . || echo "$CONFIG_SHELLS/$1")";; (*) file="$(find $CONFIG_SHELLS -name "$1*" | head -1 | grep . || echo "$CONFIG_SHELLS/$1")";;
esac esac
test -f "$file" || return 1
checksum="$(md5sum "$file")" checksum="$(md5sum "$file")"
$EDITOR $(test "$line" && echo "+$line") "${file%:*}" $EDITOR $(test "$line" && echo "+$line") "${file%:*}"
test "$checksum" != "$(md5sum $file)" && source "$HOME/.zprofile" && exec $SHELL test "$checksum" != "$(md5sum $file)" && source "$HOME/.zprofile" && exec $SHELL
} }
# Edit a file in the PATH
edbin() {
file="$(f="$(which $1 2>/dev/null)" && test -f "$f" && echo $f || edshell -f "$1" || echo "$HOME/.local/bin/scripts/$1")"
edit "$file"
}
# Edit zsh completion
edcomp() { edcomp() {
file=$(echo "$1" | sed 's/^\([^_]\)/_\1/') file=$(echo "$1" | sed 's/^\([^_]\)/_\1/')
$EDITOR "${fpath[-1]}/$file" $EDITOR "${fpath[-1]}/$file"
@ -111,12 +121,14 @@ alias syslog='less +F /var/log/syslog'
alias sc='sudo systemctl' alias sc='sudo systemctl'
alias sce='sudo systemctl enable --now' alias sce='sudo systemctl enable --now'
alias scd='sudo systemctl disable --now'
scs() { scs() {
systemctl --user status "*$1*" "$1" || systemctl --user status "*$1*" "$1" ||
sudo systemctl status "*$1*" "$1" sudo systemctl status "*$1*" "$1"
} }
alias scu='systemctl --user' alias scu='systemctl --user'
alias scue='systemctl --user enable --now' alias scue='systemctl --user enable --now'
alias scud='systemctl --user disable --now'
# Restart matching systemctl service # Restart matching systemctl service
scb() { scb() {

View File

@ -1,3 +0,0 @@
#!/bin/sh
file="$(f="$(which $1 2>/dev/null)" && test -f "$f" && echo $f || echo "$HOME/.local/bin/scripts/$1")"
edit "$file"