fish: add ghq_rm and dir_prune functions

This commit is contained in:
Hoang Nguyen 2023-07-04 00:00:00 +07:00
parent 76e7e9cb64
commit d36da1b5b8
Signed by: folliehiyuki
GPG Key ID: B0567C20730E9B11
3 changed files with 38 additions and 4 deletions

View File

@ -0,0 +1,18 @@
function ghq_rm
set -l projects (ghq list --exact | fzf \
--multi \
--prompt "Project: " \
--preview 'lsd -1FAL --group-dirs first --icon always --color always {}' \
)
if test -n "$projects"
for proj in $projects
read -l -P (printf "Delete project \033[1;33m$proj\033[0m? [y/N]") confirm
if test "$confirm" = "y"
set -l proj_dir (ghq list --full-path "$proj")
rm -rf "$proj_dir"
rmdir -p --ignore-fail-on-non-empty (dirname "$proj_dir")
end
end
end
end

View File

@ -22,6 +22,8 @@
dest: functions/
- src: ghq_cd.fish
dest: functions/
- src: ghq_rm.fish
dest: functions/
- name: fish | Copy config templates
template:

View File

@ -39,9 +39,23 @@ abbr youflac 'yt-dlp --extract-audio --audio-format flac --audio-quality 0'
abbr youlist 'yt-dlp --yes-playlist'
# Lazy cd-ing
function multicd; echo cd (string repeat -n (math (string length -- $argv[1]) - 1) ../); end
abbr dotdot --regex '^\.\.+$' --function multicd
function __multicd; echo cd (string repeat -n (math (string length -- $argv[1]) - 1) ../); end
abbr dotdot --regex '^\.\.+$' --function __multicd
# !! (previous command)
function last_history_item; echo $history[1]; end
abbr '!!' --position anywhere --function last_history_item
function __last_history_item; echo $history[1]; end
abbr '!!' --position anywhere --function __last_history_item
# Other nice things
function dir_prune
if test -d "$argv[1]"
printf "==> Prune directory \033[1;33m$argv[1]\033[0m\n"
for dir in (fd --full-path "$argv[1]" --type empty --type directory)
echo "+ $dir"
rmdir -p --ignore-fail-on-non-empty "$dir"
end
else
printf "\033[1;31m$argv[1]\033[0m is not a directory\n"
return 1
end
end