bin: revamp IGNOREDIRS and rd, add d alias & zf script for zoxide

This commit is contained in:
xeruf 2021-07-07 00:48:35 +02:00
parent 5f287dde27
commit fa524625d9
8 changed files with 57 additions and 25 deletions

View File

@ -12,8 +12,8 @@ fi
alias h='help'
alias info='info --vi-keys'
d() { cd $(zf "$@") }
alias c=z
alias d=z
alias v=edit
xdh="$XDG_DATA_HOME"
@ -33,18 +33,27 @@ which lsb_release >/dev/null && export DIST=$(lsb_release --id | cut -d' ' -f2)
compdef help=info
unalias rd 2>/dev/null
rd() {
while test $# -gt 0
for f in "$@"
do
test -d "$1" && find "$1" -maxdepth 1 -type d -empty -printf "Removing %p\n" -delete || rm -iv "$@"
if test -d "$f"; then
if test -d "$f/.git"
then echo "Force delete git project?" && read answer && test "$answer" = "y" && rm -rf "$f"
else find "$f" -maxdepth 1 -type d -empty -printf "Removing empty %p\n" -delete
fi
else rm -i "$f"
fi
shift
done
}
rr() { mv "$@" /tmp }
# like "which", but shows contents if it resolves to a file
wh() {
res=$(which "$@")
test -r "$res" && b --style=numbers,header "$res" || echo "$res"
if expr "$res" : "${@:$#}: aliased to" >/dev/null
then echo "$res" && wh $(expr "$res" : "${@:$#}: aliased to ${@:$#} " >/dev/null && echo "-p") $(echo "$res" | cut -d' ' -f4)
# use command which for other shells
else test -r "$res" && b --style=header "$res" || echo "$res" | bat --style=plain --language=sh
fi
}
compdef wh=which
@ -84,10 +93,10 @@ edconf() {
test "$sel" && ((echo "$sel" | cat - "$conf_cache" | head -30 >"$conf_tmp" && mv "$conf_tmp" "$conf_cache") & edit "$sel")
}
alias hist='print -z $(history | fzf --nth 4.. | tr -s " " | cut -d" " -f5-)'
alias hist='print -z $(history | tac | fzf --tiebreak=index | tr -s " " | cut -d" " -f5-)'
CONFIG_SHELL_FUNCTIONS="${BASH_SOURCE[0]:-${(%):-%x}}"
alias r="reset && exec zsh"
alias rs="reset && exec zsh"
edcomp() {
file=$(echo "$1" | sed 's/^\([^_]\)/_\1/')
$EDITOR "${fpath[-1]}/$file"
@ -155,9 +164,8 @@ xo() {
done
}
alias sqli='rlwrap sqlite3 -column -header -cmd .tables'
__loci='locate --ignore-case --basename'
alias loc="noglob $__loci"
alias uloc="noglob sudo updatedb && $__loci"
loc() { noglob locate --ignore-case --basename --existing "$@" | grep --color=always "$@" | less -F }
alias uloc='noglob sudo updatedb && loc'
alias syslog='less +F /var/log/syslog'
alias println='printf "\n"'
alias graphics='lspci -vnn | grep VGA --color=never && xrandr --listproviders'
@ -189,8 +197,8 @@ alias jcl='sudo SYSTEMD_LESS=FRKi journalctl --boot --no-hostname -e'
alias jc='jcl -u'
alias jcj='jcl -o json-pretty -u'
alias grp='grep --line-number --ignore-case --binary-files=without-match --directories=skip'
alias grpr="grp --recursive --exclude-dir={$IGNOREDIRS}"
alias grp='grep --color=auto --line-number --ignore-case --binary-files=without-match --directories=skip'
grpr() { grp --color=always --recursive $(echo $IGNOREDIRS | sed 's/-x/--exclude-dir/g') "$@" | less -F }
# Recover stray swap files from neovim
alias vrec="ls $XDG_DATA_HOME/nvim/swap | sed 's/\%/\//g' | sed 's|\(.*\)\..*|\1|' | head -1 | xargs -r nvim"
@ -352,8 +360,8 @@ resetdocker() {
typeset -A _clean_map
if test "$BASH_VERSION"
then _clean_map=([c]=$XDG_CACHE_HOME [t]=/var/tmp)
else _clean_map=(c $XDG_CACHE_HOME t /var/tmp)
then _clean_map=([h]=$XDG_CACHE_HOME [t]=/var/tmp)
else _clean_map=(h $XDG_CACHE_HOME t /var/tmp)
fi
_clean_folders=()
clean() {
@ -363,8 +371,8 @@ clean() {
highlight "g to clean gradle"
if [[ $1 =~ "g" ]]; then
find ${GRADLE_USER_HOME:-$HOME/.gradle} -mindepth 1 -maxdepth 1 -type d -exec rm -r {} \; -print
find $projects_dir -name .gradle -print -exec rm -r {} \;
find ${GRADLE_USER_HOME:-$HOME/.gradle} -mindepth 1 -maxdepth 1 -type d -print -exec rm -r {} +
find $projects_dir -name .gradle -print -exec rm -r {} +
fi
highlight "m to clean mac-files"
@ -373,6 +381,12 @@ clean() {
find -name '*.DS_Store' -delete
fi
highlight "c to clean local caches"
if [[ $1 =~ "c" ]]; then
find -name ".gradle" -o -name "generated" -o -name "dist_newstyle" -o -name "cache" -o -name "node_modules" -print -exec rm -r {} +
find -name "*build" -ok rm -r {} \; -prune
fi
if test "$BASH_VERSION"; then
for k in "${!_clean_map[@]}"; do
highlight "$k to delete $_clean_map[$k]"

View File

@ -5,13 +5,13 @@
for last; do true; done
last=${last:-.}
file "$last" | grep -v --color=never 'directory$'
tput setaf 4 && file "$last" | grep -v --color=never 'directory$'
test -e "$last" || exit 1
case "$(file --dereference --mime "$last")" in
*inode/directory*) ls -l --color=always --human-readable --group-directories-first --file-type --dereference-command-line --all "$@";;
*binary) ;;
*) $(test -f "$last" -a ! -r "$last" && echo "sudo") bat --style header --pager "less --LONG-PROMPT --quit-if-one-screen" "$@"
*) $(test -f "$last" -a ! -r "$last" && echo "sudo") bat --style header "$@"
tput setaf 3 && stat --format '%A size %sB, birth: %.10w mod %.10y' "$last"
;;
esac

View File

@ -1,6 +1,5 @@
#!/bin/sh
set -o pipefail
# interactive diff with pagination
diff --color=always --report-identical-files -U 2 "$@" |
diffr --colors refine-added:none:background:0x33,0x66,0x33:bold --colors added:none:background:0x33,0x44,0x33 --colors refine-removed:none:background:0x66,0x33,0x33:bold --colors removed:none:background:0x44,0x33,0x33 |
diff-color --report-identical-files "$@" |
less --RAW-CONTROL-CHARS --quit-on-intr --quit-if-one-screen

4
.local/bin/scripts/diff-color Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
# Colorize with diffr
diff --color=always -U 2 "$@" |
diffr --colors refine-added:none:background:0x33,0x66,0x33:bold --colors added:none:background:0x33,0x44,0x33 --colors refine-removed:none:background:0x66,0x33,0x33:bold --colors removed:none:background:0x44,0x33,0x33

View File

@ -1,8 +1,8 @@
#!/bin/sh
case $1 in
(vlc) unbuffer vlc --full-help "${@:2}" | ${PAGER:-less} --quit-if-one-screen;;
(zmv) # https://unix.stackexchange.com/questions/19290/zmv-for-zsh-dry-runs-and-man-pages
(zsh|zmv) # https://unix.stackexchange.com/questions/19290/zmv-for-zsh-dry-runs-and-man-pages
# need to install zsh-doc for info
info --index-search=zmv zsh || LESS="$LESS +/^ *zmv *\\[" man zshcontrib;;
(*) man "$@" || "$@" --help | ${PAGER:-less} --quit-if-one-screen;;
info --vi-keys --index-search="${@:$#}" zsh || LESS="$LESS +/^ *zmv *\\[" man zshcontrib;;
(*) info "$1" -w | grep -v "manpages" && pinfo "$@" || man "$@" || "$@" --help | ${PAGER:-less} --quit-if-one-screen;;
esac

View File

@ -1,2 +1,3 @@
#!/bin/sh
diff -r $1 $2 -x .git -x .idea -x .gradle -x build -x cmake_build -x dist_newstyle
# Diff project directories, excluding any generated content
diff-color -r $IGNOREDIRS "$@" | less -F

14
.local/bin/scripts/zf Executable file
View File

@ -0,0 +1,14 @@
#!/bin/sh
# Quick directory switcher based on zoxide and fzf
if test -d "$1" -o "$1" = "-"
then echo "$@"
else
set -o noglob
query=$(zoxide query -sl "$@")
# First find out whether there is an obvious match (score at least ten times that of runner-up)
# If not select with fzf, using locate to find extra options
( expr $(echo "$query" | sed 'N;s|/.*\n|> 10 *|;q' | sed 's| */.*||') >/dev/null &&
echo "$query" | head -1 ||
( echo "$query"; locate --basename --existing "$@" | while read -r file; do test -d "$file" && echo "$file"; done | sed 's/^/ 0 /' ) |
fzf -0 -1 -n2.. --tiebreak=index --preview="ls -a --color --human-readable --group-directories-first --file-type {2..}" --preview-window=20% ) | tr -s ' ' | cut -d' ' -f3-
fi

View File

@ -45,7 +45,7 @@ export CCACHE_DIR="$XDG_CACHE_HOME"/ccache
# environment
which nvim >/dev/null && export EDITOR='nvim' || export EDITOR='vim'
export LESS='--RAW-CONTROL-CHARS --ignore-case --incsearch --LONG-PROMPT --jump-target=5'
export IGNOREDIRS=".sync,.stfolder,.git,out,build,dev"
export IGNOREDIRS="-x dev -x .sync -x .stfolder -x .git -x .gradle -x .idea -x out -x *build -x dist_newstyle -x generated -x cache -x node_modules"
# red stderr
test -f "/usr/lib/libstderred.so" && export LD_PRELOAD="/usr/lib/libstderred.so${LD_PRELOAD:+:$LD_PRELOAD}"
# software config