From 58ef3cca9995de8fea17a49644ca08e1bb5f75ee Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Sun, 31 Oct 2021 19:28:46 +0100 Subject: [PATCH] config/shell: improve edbin & loca --- .config/shell/browse | 4 ++-- .config/shell/functions | 16 ++++++++++++++-- .local/bin/scripts/edbin | 3 --- 3 files changed, 16 insertions(+), 7 deletions(-) delete mode 100755 .local/bin/scripts/edbin diff --git a/.config/shell/browse b/.config/shell/browse index f58bcc9..7c24f51 100644 --- a/.config/shell/browse +++ b/.config/shell/browse @@ -45,7 +45,7 @@ alias uloc='noglob sudo updatedb && loci' locei() { locate --all --basename "\\$1" "$@" | fselect } alias loce='noglob locei' # 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 alias c=z @@ -57,7 +57,7 @@ d() { # 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 then echo "$query" | head -1 - else echo "$query"; locz "$@" + else test -n "$query" && echo "$query"; locz "$@" fi | zfz)" } di() { diff --git a/.config/shell/functions b/.config/shell/functions index 9cd9df4..47523f1 100644 --- a/.config/shell/functions +++ b/.config/shell/functions @@ -62,6 +62,7 @@ pathadd() { 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-)' +# Edit shell config files CONFIG_SHELL_FUNCTIONS="${BASH_SOURCE[0]:-${(%):-%x}}" edshell() { case $1 in @@ -69,15 +70,24 @@ edshell() { (zsh) file="$CONFIG_ZSH/.zshrc";; (prof*) file="$HOME/.zprofile";; (-f) grepfile="$(grep --recursive "\(^$2()\|alias $2=\)" $CONFIG_SHELLS -n -m 1)" - file=$(echo "$grepfile" | cut -d':' -f1) - line=$(echo "$grepfile" | cut -d':' -f2);; + file="$(echo "$grepfile" | cut -d':' -f1)" + line="$(echo "$grepfile" | cut -d':' -f2)";; (*) file="$(find $CONFIG_SHELLS -name "$1*" | head -1 | grep . || echo "$CONFIG_SHELLS/$1")";; esac + test -f "$file" || return 1 checksum="$(md5sum "$file")" $EDITOR $(test "$line" && echo "+$line") "${file%:*}" 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() { file=$(echo "$1" | sed 's/^\([^_]\)/_\1/') $EDITOR "${fpath[-1]}/$file" @@ -111,12 +121,14 @@ alias syslog='less +F /var/log/syslog' alias sc='sudo systemctl' alias sce='sudo systemctl enable --now' +alias scd='sudo systemctl disable --now' scs() { systemctl --user status "*$1*" "$1" || sudo systemctl status "*$1*" "$1" } alias scu='systemctl --user' alias scue='systemctl --user enable --now' +alias scud='systemctl --user disable --now' # Restart matching systemctl service scb() { diff --git a/.local/bin/scripts/edbin b/.local/bin/scripts/edbin deleted file mode 100755 index ede8eba..0000000 --- a/.local/bin/scripts/edbin +++ /dev/null @@ -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"