From d36da1b5b81d52e2e5c4616edac9c16fe0d13c39 Mon Sep 17 00:00:00 2001 From: Hoang Nguyen Date: Tue, 4 Jul 2023 00:00:00 +0700 Subject: [PATCH] fish: add ghq_rm and dir_prune functions --- roles/config/files/fish/ghq_rm.fish | 18 ++++++++++++++++++ roles/config/tasks/fish.yml | 2 ++ roles/config/templates/fish/aliases.j2 | 22 ++++++++++++++++++---- 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 roles/config/files/fish/ghq_rm.fish diff --git a/roles/config/files/fish/ghq_rm.fish b/roles/config/files/fish/ghq_rm.fish new file mode 100644 index 0000000..4ad75ba --- /dev/null +++ b/roles/config/files/fish/ghq_rm.fish @@ -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 diff --git a/roles/config/tasks/fish.yml b/roles/config/tasks/fish.yml index 57be2df..a0e2219 100644 --- a/roles/config/tasks/fish.yml +++ b/roles/config/tasks/fish.yml @@ -22,6 +22,8 @@ dest: functions/ - src: ghq_cd.fish dest: functions/ + - src: ghq_rm.fish + dest: functions/ - name: fish | Copy config templates template: diff --git a/roles/config/templates/fish/aliases.j2 b/roles/config/templates/fish/aliases.j2 index 270083e..3cb7138 100644 --- a/roles/config/templates/fish/aliases.j2 +++ b/roles/config/templates/fish/aliases.j2 @@ -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