diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0cebbc7..a389bad 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,10 +6,10 @@ on: jobs: test: name: Approvals on Ubuntu - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install fzf run: sudo apt install -y fzf # - name: Setup tmate session @@ -24,7 +24,7 @@ jobs: runs-on: macos-latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install fzf run: brew install fzf - name: Run approval tests @@ -35,7 +35,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Run setup approval tests run: test/approve_setup @@ -44,7 +44,15 @@ jobs: runs-on: macos-latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Run setup approval tests run: test/approve_setup + shellcheck: + name: Shellcheck + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Run shellcheck tests + run: shellcheck setup fuzzycd && echo PASS diff --git a/fuzzycd b/fuzzycd index f1874b4..60dee3e 100644 --- a/fuzzycd +++ b/fuzzycd @@ -7,9 +7,9 @@ fuzzycd_run() { _fzcd_is_dirname() { if [[ -d "$1" ]]; then return 0 - + elif [[ -n "$CDPATH" ]]; then - IFS=':' read -ra cdpath <<< "$CDPATH" + IFS=':' read -ra cdpath <<<"$CDPATH" for path in "${cdpath[@]}"; do [[ -d "$path/$1" ]] && return 0 done @@ -25,32 +25,32 @@ fuzzycd_run() { _fzcd_run_fzf() { # shellcheck disable=SC2145 declare -a opts=(--query="$@" --bind="del:execute-silent(fuzzycd -d {})+reload(fuzzycd -s)" --select-1 --exit-0 --info=hidden --prompt="$ cd ") - + case "$FUZZYCD_MODE" in - "m" ) + "m") fzf --filter "$@" --exit-0 | head -1 ;; - "i" ) + "i") fzf "${opts[@]}" ;; - * ) + *) fzf "${opts[@]}" --preview='ls {}' --preview-window="border-left" ;; esac } _fzcd_dir_search() { - _fzcd_run_fzf "$@" < "$histfile" + _fzcd_run_fzf "$@" <"$histfile" } _fzcd_remember_me() { - grep -qxF "$PWD" "$histfile" || echo "$PWD" >> "$histfile" + grep -qxF "$PWD" "$histfile" || echo "$PWD" >>"$histfile" } _fzcd_create_histfile() { - mkdir -p "$(dirname "$histfile")" && touch "$histfile"; + mkdir -p "$(dirname "$histfile")" && touch "$histfile" } _fzcd_chdir() { @@ -87,7 +87,7 @@ fuzzycd_run() { _fzcd_delete_dir() { dir="${1:-$PWD}" - grep -Fxv "$dir" "$histfile" > "$HOME/.fuzzycd-history.tmp" + grep -Fxv "$dir" "$histfile" >"$HOME/.fuzzycd-history.tmp" cp "$HOME/.fuzzycd-history.tmp" "$histfile" rm -f "$HOME/.fuzzycd-history.tmp" echo "deleted $dir" @@ -126,7 +126,7 @@ fuzzycd_run() { _fzcd_chdir "$@" elif _fzcd_is_dirname "$1"; then _fzcd_chdir "$1" - else + else _fzcd_chdir_fzf "$@" fi } @@ -135,15 +135,18 @@ fuzzycd_run() { [[ -f "$histfile" ]] || _fzcd_create_histfile case "$1" in - "-l" ) FUZZYCD_MODE=i _fzcd_chdir_fzf ;; - "-v" ) _fzcd_show_version ;; - "-e" ) _fzcd_edit_histfile ;; - "-s" ) _fzcd_show_histfile ;; - "-d" ) shift ; _fzcd_delete_dir "$@" ;; - "-h" ) _fzcd_show_usage ;; - * ) _fzcd_handle_command "$@" ;; + "-l") FUZZYCD_MODE=i _fzcd_chdir_fzf ;; + "-v") _fzcd_show_version ;; + "-e") _fzcd_edit_histfile ;; + "-s") _fzcd_show_histfile ;; + "-d") + shift + _fzcd_delete_dir "$@" + ;; + "-h") _fzcd_show_usage ;; + *) _fzcd_handle_command "$@" ;; esac - } + } _fzcd_run "$@" } @@ -157,12 +160,12 @@ if [[ -n "$is_sourced" ]]; then if [[ -z "$FUZZYCD_TTY_FORCE" ]]; then case $- in *i*) ;; - *) return;; + *) return ;; esac fi - unalias cd 2> /dev/null || true + unalias cd 2>/dev/null || true cd() { - fuzzycd_run "$@"; + fuzzycd_run "$@" } fi diff --git a/op.conf b/op.conf index 37ee41b..a2446a3 100644 --- a/op.conf +++ b/op.conf @@ -1,2 +1,3 @@ -shellcheck: shellcheck setup fuzzycd +shellcheck: shellcheck setup fuzzycd && echo PASS +shfmt: shfmt -d -i 2 -ci setup fuzzycd && echo PASS test: test/approve diff --git a/setup b/setup index dad69d3..bd772e8 100755 --- a/setup +++ b/setup @@ -9,14 +9,14 @@ fuzzy_cd_setup() { echo "=== Skipping $file" else echo "=== Amending $file" - printf "source /usr/local/bin/fuzzycd\n" >> "$file" + printf "source /usr/local/bin/fuzzycd\n" >>"$file" fi patched="yes" } download_script() { echo "=== Saving fuzzycd to /usr/local/bin" - + sudo='' if [[ $EUID -ne 0 ]]; then sudo='sudo' @@ -41,7 +41,6 @@ fuzzy_cd_setup() { echo " Add 'source ~/.fuzzy-cd/fuzzy-cd' to your shell's initialization script" exit 1 fi - } download_script @@ -49,4 +48,4 @@ fuzzy_cd_setup() { show_exit_message } -fuzzy_cd_setup \ No newline at end of file +fuzzy_cd_setup