From a15863b0e596e4537a56a35312e4bed28c13f822 Mon Sep 17 00:00:00 2001 From: gwbeip Date: Thu, 22 Jan 2026 22:38:02 +0800 Subject: [PATCH] interactive cd --- zsh/functions/interactive_cd.sh | 19 +++++++++++++++++++ zsh/zshrc | 22 ++++++++++------------ 2 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 zsh/functions/interactive_cd.sh diff --git a/zsh/functions/interactive_cd.sh b/zsh/functions/interactive_cd.sh new file mode 100644 index 0000000..859fd4c --- /dev/null +++ b/zsh/functions/interactive_cd.sh @@ -0,0 +1,19 @@ +function cdi() { + selected_dir="" + if (( $+commands[fzf] )); then + if (( $+commands[fd] )); then + if [[ $1 == "-I" ]]; then + selected_dir=$(fd --type d --hidden --no-ignore --exclude .git | fzf) + else + selected_dir=$(fd --type d --hidden --exclude .git | fzf) + fi + else + selected_dir=$(find . -type d -name '.git' -prune -o -type d -print | fzf) + fi + if [[ -n $selected_dir ]]; then + cd $selected_dir + fi + else + echo "[fzf] is not installed" + fi +} diff --git a/zsh/zshrc b/zsh/zshrc index 415db69..e287d70 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -2,18 +2,20 @@ # path -> settings -> alias -> functions -> plugins -> prompt -if [ -n "${ZSH_VERSION}" ]; then - _source="${(%):-%x}" - _path=$(dirname "$(realpath "$_source")") - unset _source -else +if [ ! -n "${ZSH_VERSION}" ]; then echo "Unsupported shell" - exit 1 + return 1 fi +# get the dir name that current file in +function get_current_dir_name { + _source="${(%):-%x}" + _path=$(dirname "$(realpath "$_source")") + echo $_path +} + # Set basic path to zsh-polyjuice installation -export ZSH_POLYJUICE_PATH="$_path" -unset _path +export ZSH_POLYJUICE_PATH=$(get_current_dir_name) export ZSH_PLUGINS_PATH="$ZSH_POLYJUICE_PATH/plugins" export ZSH_ALIAS_PATH="$ZSH_POLYJUICE_PATH/alias" export ZSH_SETTINGS_PATH="$ZSH_POLYJUICE_PATH/settings" @@ -51,10 +53,6 @@ source $ZSH_PLUGINS_PATH/ohmyzsh/plugins/zoxide/zoxide.plugin.zsh source $ZSH_PLUGINS_PATH/ohmyzsh/plugins/python/python.plugin.zsh -function cdi() { - cd $(find . -type d | fzf) -} - # using starship as prompt if (( $+commands[starship] )); then eval "$(starship init zsh)"