config/shell: expand zoxide & clean functions

- d/di alias based on zf, locz and zfz
- update clean function
This commit is contained in:
xeruf 2021-07-25 21:54:27 +02:00
parent d401be9aab
commit f334607d4f
4 changed files with 32 additions and 16 deletions

View File

@ -13,7 +13,19 @@ alias h='help'
compdef help=which compdef help=which
alias info='info --vi-keys' alias info='info --vi-keys'
d() { cd $(zf "$@") } d() {
local query="$(zf "$@")"
# First find out whether there is an obvious match
# (at least 3 matches & score at least ten times above runner-up or score above 20)
# If not select with fzf, using locate to find extra options
cd "$(if expr "$(echo "$query" | head -1 | cut -d' ' -f2)" \> 20 \& $(echo "$query" | sed 'N;s|/.*\n|> 10 *|;q' | sed 's| */.*||') >/dev/null 2>&1
then echo "$query" | head -1
else echo "$query"; locz "$@"
fi | zfz)"
}
di() {
cd "$( ( zf "$@"; locz "$@" ) | zfz)"
}
alias c=z alias c=z
alias v=edit alias v=edit
@ -78,7 +90,7 @@ alias dedup='awk '"'"'!a[$0]++'"'"
listconf() { listconf() {
{ cat "$conf_cache"; test -f "$conf_extra" && cat "$conf_extra"; { cat "$conf_cache"; test -f "$conf_extra" && cat "$conf_extra";
fd --hidden --type file --size -1m --max-depth 1 . ~; fd --hidden --type file --size -1m --max-depth 1 . ~;
sudo fd --hidden --type file --size -1m --max-depth 3 . --full-path "$XDG_CONFIG_HOME" /etc } | dedup sudo find "$XDG_CONFIG_HOME" /etc -maxdepth 3 -type f -exec grep -lI '' {} + } | dedup
} }
edconf() { edconf() {
@ -247,7 +259,7 @@ updateDeps() {
} }
alias updateKotlin="updateDeps build.gradle.kts 'kotlin(\"jvm\") version ' --version" alias updateKotlin="updateDeps build.gradle.kts 'kotlin(\"jvm\") version ' --version"
alias updateGradle='updateDeps gradle-wrapper.properties "services.gradle.org\/distributions\/gradle-" --version' alias updateGradle='updateDeps gradle-wrapper.properties "services.gradle.org\/distributions\/gradle-" --version'
alias updateUtils='updateDeps build.gradle.kts '\''\"com.github.Xerus2000.util\", \".*\", \"'\'' --pattern '\''[^\"]\+'\'' --version' alias updateUtils="updateDeps build.gradle.kts '"'"com.github.Xerus2000.util", ".*", "'" --pattern '[^\"]\+' --version"
# Kill all shell background processes # Kill all shell background processes
alias killbg='kill ${${(v)jobstates##*:*:}%=*}' alias killbg='kill ${${(v)jobstates##*:*:}%=*}'
@ -378,14 +390,17 @@ clean() {
highlight "m to clean mac-files" highlight "m to clean mac-files"
if [[ $1 =~ "m" ]]; then if [[ $1 =~ "m" ]]; then
find -iname '.spotlight*' -print -exec rm -r {} \; find -iname '.spotlight*' -exec rm -rI {} +
find -name '*.DS_Store' -delete find -name '*.DS_Store' -delete
fi fi
highlight "e to clean electron caches"
[[ $1 =~ "e" ]] && find "$XDG_CONFIG_HOME" -type d -name "*Cache" -exec rm -r {} + -prune
highlight "c to clean local caches" highlight "c to clean local caches"
if [[ $1 =~ "c" ]]; then 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 ".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 find -name "*build" -exec rm -rI {} +
fi fi
if test "$BASH_VERSION"; then if test "$BASH_VERSION"; then
@ -407,9 +422,8 @@ clean() {
export aptclean_last=$aptclean_cur export aptclean_last=$aptclean_cur
fi fi
highlight "f to delete empty folders"
highlight "e to delete empty folders" [[ $1 =~ "f" ]] && find -empty -type d -delete -print
[[ $1 =~ "e" ]] && find -empty -type d -delete -print
highlight "o to optimize extensively" highlight "o to optimize extensively"
if [[ $1 =~ "o" ]]; then if [[ $1 =~ "o" ]]; then

5
.local/bin/scripts/locz Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
# Locate existing directories in zoxide format
locate --basename --ignore-case "$@" |
while read -r file; do test -d "$file" && echo "$file"; done |
sed 's/^/ 0 /'

View File

@ -1,14 +1,8 @@
#!/bin/sh #!/bin/sh
# Quick directory switcher based on zoxide and fzf # Listing for quick directory switcher based on zoxide and fzf
if test -d "$1" -o "$1" = "-" if test -d "$1" -o "$1" = "-"
then echo "$@" then echo "$@"
else else
set -o noglob set -o noglob
query=$(zoxide query -sl "$@") 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 2>&1 &&
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 fi

3
.local/bin/scripts/zfz Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
# fzf for zoxide
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-