Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Housekeeping #14

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
47 changes: 25 additions & 22 deletions fuzzycd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -126,7 +126,7 @@ fuzzycd_run() {
_fzcd_chdir "$@"
elif _fzcd_is_dirname "$1"; then
_fzcd_chdir "$1"
else
else
_fzcd_chdir_fzf "$@"
fi
}
Expand All @@ -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 "$@"
}
Expand All @@ -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
3 changes: 2 additions & 1 deletion op.conf
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions setup
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -41,12 +41,11 @@ fuzzy_cd_setup() {
echo " Add 'source ~/.fuzzy-cd/fuzzy-cd' to your shell's initialization script"
exit 1
fi

}

download_script
patch_startup_files
show_exit_message
}

fuzzy_cd_setup
fuzzy_cd_setup