bin: revamp IGNOREDIRS and rd, add d alias & zf script for zoxide
This commit is contained in:
parent
5f287dde27
commit
fa524625d9
|
@ -12,8 +12,8 @@ fi
|
||||||
alias h='help'
|
alias h='help'
|
||||||
alias info='info --vi-keys'
|
alias info='info --vi-keys'
|
||||||
|
|
||||||
|
d() { cd $(zf "$@") }
|
||||||
alias c=z
|
alias c=z
|
||||||
alias d=z
|
|
||||||
alias v=edit
|
alias v=edit
|
||||||
|
|
||||||
xdh="$XDG_DATA_HOME"
|
xdh="$XDG_DATA_HOME"
|
||||||
|
@ -33,18 +33,27 @@ which lsb_release >/dev/null && export DIST=$(lsb_release --id | cut -d' ' -f2)
|
||||||
compdef help=info
|
compdef help=info
|
||||||
unalias rd 2>/dev/null
|
unalias rd 2>/dev/null
|
||||||
rd() {
|
rd() {
|
||||||
while test $# -gt 0
|
for f in "$@"
|
||||||
do
|
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
|
shift
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
rr() { mv "$@" /tmp }
|
|
||||||
|
|
||||||
# like "which", but shows contents if it resolves to a file
|
# like "which", but shows contents if it resolves to a file
|
||||||
wh() {
|
wh() {
|
||||||
res=$(which "$@")
|
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
|
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")
|
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}}"
|
CONFIG_SHELL_FUNCTIONS="${BASH_SOURCE[0]:-${(%):-%x}}"
|
||||||
alias r="reset && exec zsh"
|
alias rs="reset && exec zsh"
|
||||||
edcomp() {
|
edcomp() {
|
||||||
file=$(echo "$1" | sed 's/^\([^_]\)/_\1/')
|
file=$(echo "$1" | sed 's/^\([^_]\)/_\1/')
|
||||||
$EDITOR "${fpath[-1]}/$file"
|
$EDITOR "${fpath[-1]}/$file"
|
||||||
|
@ -155,9 +164,8 @@ xo() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
alias sqli='rlwrap sqlite3 -column -header -cmd .tables'
|
alias sqli='rlwrap sqlite3 -column -header -cmd .tables'
|
||||||
__loci='locate --ignore-case --basename'
|
loc() { noglob locate --ignore-case --basename --existing "$@" | grep --color=always "$@" | less -F }
|
||||||
alias loc="noglob $__loci"
|
alias uloc='noglob sudo updatedb && loc'
|
||||||
alias uloc="noglob sudo updatedb && $__loci"
|
|
||||||
alias syslog='less +F /var/log/syslog'
|
alias syslog='less +F /var/log/syslog'
|
||||||
alias println='printf "\n"'
|
alias println='printf "\n"'
|
||||||
alias graphics='lspci -vnn | grep VGA --color=never && xrandr --listproviders'
|
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 jc='jcl -u'
|
||||||
alias jcj='jcl -o json-pretty -u'
|
alias jcj='jcl -o json-pretty -u'
|
||||||
|
|
||||||
alias grp='grep --line-number --ignore-case --binary-files=without-match --directories=skip'
|
alias grp='grep --color=auto --line-number --ignore-case --binary-files=without-match --directories=skip'
|
||||||
alias grpr="grp --recursive --exclude-dir={$IGNOREDIRS}"
|
grpr() { grp --color=always --recursive $(echo $IGNOREDIRS | sed 's/-x/--exclude-dir/g') "$@" | less -F }
|
||||||
|
|
||||||
# Recover stray swap files from neovim
|
# 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"
|
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
|
typeset -A _clean_map
|
||||||
if test "$BASH_VERSION"
|
if test "$BASH_VERSION"
|
||||||
then _clean_map=([c]=$XDG_CACHE_HOME [t]=/var/tmp)
|
then _clean_map=([h]=$XDG_CACHE_HOME [t]=/var/tmp)
|
||||||
else _clean_map=(c $XDG_CACHE_HOME t /var/tmp)
|
else _clean_map=(h $XDG_CACHE_HOME t /var/tmp)
|
||||||
fi
|
fi
|
||||||
_clean_folders=()
|
_clean_folders=()
|
||||||
clean() {
|
clean() {
|
||||||
|
@ -363,8 +371,8 @@ clean() {
|
||||||
|
|
||||||
highlight "g to clean gradle"
|
highlight "g to clean gradle"
|
||||||
if [[ $1 =~ "g" ]]; then
|
if [[ $1 =~ "g" ]]; then
|
||||||
find ${GRADLE_USER_HOME:-$HOME/.gradle} -mindepth 1 -maxdepth 1 -type d -exec rm -r {} \; -print
|
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 {} \;
|
find $projects_dir -name .gradle -print -exec rm -r {} +
|
||||||
fi
|
fi
|
||||||
|
|
||||||
highlight "m to clean mac-files"
|
highlight "m to clean mac-files"
|
||||||
|
@ -373,6 +381,12 @@ clean() {
|
||||||
find -name '*.DS_Store' -delete
|
find -name '*.DS_Store' -delete
|
||||||
fi
|
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
|
if test "$BASH_VERSION"; then
|
||||||
for k in "${!_clean_map[@]}"; do
|
for k in "${!_clean_map[@]}"; do
|
||||||
highlight "$k to delete $_clean_map[$k]"
|
highlight "$k to delete $_clean_map[$k]"
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
for last; do true; done
|
for last; do true; done
|
||||||
last=${last:-.}
|
last=${last:-.}
|
||||||
|
|
||||||
file "$last" | grep -v --color=never 'directory$'
|
tput setaf 4 && file "$last" | grep -v --color=never 'directory$'
|
||||||
test -e "$last" || exit 1
|
test -e "$last" || exit 1
|
||||||
|
|
||||||
case "$(file --dereference --mime "$last")" in
|
case "$(file --dereference --mime "$last")" in
|
||||||
*inode/directory*) ls -l --color=always --human-readable --group-directories-first --file-type --dereference-command-line --all "$@";;
|
*inode/directory*) ls -l --color=always --human-readable --group-directories-first --file-type --dereference-command-line --all "$@";;
|
||||||
*binary) ;;
|
*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"
|
tput setaf 3 && stat --format '%A size %sB, birth: %.10w mod %.10y' "$last"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
# interactive diff with pagination
|
# interactive diff with pagination
|
||||||
diff --color=always --report-identical-files -U 2 "$@" |
|
diff-color --report-identical-files "$@" |
|
||||||
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 |
|
|
||||||
less --RAW-CONTROL-CHARS --quit-on-intr --quit-if-one-screen
|
less --RAW-CONTROL-CHARS --quit-on-intr --quit-if-one-screen
|
||||||
|
|
|
@ -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
|
|
@ -1,8 +1,8 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
case $1 in
|
case $1 in
|
||||||
(vlc) unbuffer vlc --full-help "${@:2}" | ${PAGER:-less} --quit-if-one-screen;;
|
(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
|
# need to install zsh-doc for info
|
||||||
info --index-search=zmv zsh || LESS="$LESS +/^ *zmv *\\[" man zshcontrib;;
|
info --vi-keys --index-search="${@:$#}" zsh || LESS="$LESS +/^ *zmv *\\[" man zshcontrib;;
|
||||||
(*) man "$@" || "$@" --help | ${PAGER:-less} --quit-if-one-screen;;
|
(*) info "$1" -w | grep -v "manpages" && pinfo "$@" || man "$@" || "$@" --help | ${PAGER:-less} --quit-if-one-screen;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
#!/bin/sh
|
#!/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
|
||||||
|
|
|
@ -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
|
|
@ -45,7 +45,7 @@ export CCACHE_DIR="$XDG_CACHE_HOME"/ccache
|
||||||
# environment
|
# environment
|
||||||
which nvim >/dev/null && export EDITOR='nvim' || export EDITOR='vim'
|
which nvim >/dev/null && export EDITOR='nvim' || export EDITOR='vim'
|
||||||
export LESS='--RAW-CONTROL-CHARS --ignore-case --incsearch --LONG-PROMPT --jump-target=5'
|
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
|
# red stderr
|
||||||
test -f "/usr/lib/libstderred.so" && export LD_PRELOAD="/usr/lib/libstderred.so${LD_PRELOAD:+:$LD_PRELOAD}"
|
test -f "/usr/lib/libstderred.so" && export LD_PRELOAD="/usr/lib/libstderred.so${LD_PRELOAD:+:$LD_PRELOAD}"
|
||||||
# software config
|
# software config
|
||||||
|
|
Loading…
Reference in New Issue