From 69e74204b2ccf782dfa780095e86dd5a63726f6d Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Fri, 11 Oct 2019 14:33:16 -0300 Subject: [PATCH] Minor changes (#122) --- README.md | 15 ++++++++++---- cheats/android.cheat | 27 ++++++++++++++++++++++++++ cheats/awk.cheat | 4 ---- cheats/git.cheat | 6 +++++- cheats/misc.cheat | 18 +++++++++++++++++ cheats/osx.cheat | 20 +++++++++++++++++++ navi | 6 +++--- navi.plugin.bash | 2 +- navi.plugin.fish | 21 ++++++++++++++++++++ scripts/install | 4 ++-- scripts/lint | 6 +++--- scripts/playground | 6 +++--- scripts/release | 8 ++++---- scripts/update | 6 +++--- src/main.sh | 42 ++++++++++++++++++++++++---------------- src/opts.sh | 3 ++- src/ui.sh | 2 +- src/version.sh | 2 +- test/core.sh | 6 +++--- test/integration_test.sh | 4 ++-- test/run | 6 +++--- 21 files changed, 158 insertions(+), 56 deletions(-) create mode 100644 cheats/android.cheat delete mode 100644 cheats/awk.cheat create mode 100644 cheats/misc.cheat create mode 100644 cheats/osx.cheat create mode 100644 navi.plugin.fish diff --git a/README.md b/README.md index 7cb5bfb..188d62c 100644 --- a/README.md +++ b/README.md @@ -50,13 +50,20 @@ brew install denisidoro/tools/navi ### Using git -Alternatively, you can `git clone` this repository and run `make`: +Alternatively, you can `git clone` this repository: ```sh git clone --depth 1 https://github.com/denisidoro/navi /opt/navi cd /opt/navi -sudo make install # or ./scripts/install /some/path -# install fzf: https://github.com/junegunn/fzf + +# to install in your $PATH +sudo make install + +# to install in an arbitrary folder +./scripts/install /some/path + +# install fzf +# refer to https://github.com/junegunn/fzf ``` ### Using oh-my-zsh @@ -76,7 +83,7 @@ plugins=(docker tmux fzf navi) Finally, you can use it as a [shell widget](#shell-widget). -This method has the advantage of not requiring root to install and disadvantage of not allowing you to invoke the script by calling `navi` (unless you add an alias to it or copy it to a folder in `$PATH`). +This method has the advantage of not requiring root to install and the disadvantage of not allowing you to invoke the script by calling `navi` (unless you add an alias to it or copy it to a folder in `$PATH`). Upgrading --------- diff --git a/cheats/android.cheat b/cheats/android.cheat new file mode 100644 index 0000000..71e5116 --- /dev/null +++ b/cheats/android.cheat @@ -0,0 +1,27 @@ +% android, device + +# Get property +adb -s shell getprop + +# Install APK +adb -s install -r + +# Uninstall package +adb -s uninstall -r + +# Clear user data for package +adb -s shell pm clear + +# Dispatch a deep-link / open URI +adb -s shell am start + +$ device: adb devices --- --headers 1 --column 1 + + + +% android, emulator + +# Start emulator +"$ANDROID_HOME/tools/emulator" -avd -netdelay none -netspeed full + +$ emulator: "$ANDROID_HOME/tools/emulator" -list-avds \ No newline at end of file diff --git a/cheats/awk.cheat b/cheats/awk.cheat deleted file mode 100644 index 8670cb6..0000000 --- a/cheats/awk.cheat +++ /dev/null @@ -1,4 +0,0 @@ -% awk, string - -# Print last column -awk '{print $NF}' diff --git a/cheats/git.cheat b/cheats/git.cheat index 04e5131..85b7bbb 100644 --- a/cheats/git.cheat +++ b/cheats/git.cheat @@ -74,6 +74,10 @@ git clean -dxf git rebase master -S -f # See all open pull requests of a user on Github -url::open 'https://github.com/pulls?&q=author:+is:open+is:pr' +navi fn url::open 'https://github.com/pulls?&q=author:+is:open+is:pr' + +# Checkout a branch from a fork +git fetch origin pull//head:pr/ \ + && git checkout pr/ $ branch: git branch | awk '{print $NF}' diff --git a/cheats/misc.cheat b/cheats/misc.cheat new file mode 100644 index 0000000..10a0753 --- /dev/null +++ b/cheats/misc.cheat @@ -0,0 +1,18 @@ +% weather + +# Show weather info for current location +curl -s "wttr.in" \ + | grep -v "New feature" \ + | grep -v Follow + +# Show weather info for a specific location +curl -s "wttr.in/" \ + | grep -v "New feature" \ + | grep -v Follow + + + +% qr code + +# Create a QR code with the content +echo | curl -F-=\<- qrenco.de \ No newline at end of file diff --git a/cheats/osx.cheat b/cheats/osx.cheat new file mode 100644 index 0000000..5c374c3 --- /dev/null +++ b/cheats/osx.cheat @@ -0,0 +1,20 @@ +% osx, mac os + +# Lock system +pmset displaysleepnow + +# Show hidden files in Finder +defaults write com.apple.finder AppleShowAllFiles -bool true; \ + killall Finder + +# Hide hidden files in Finder +defaults write com.apple.finder AppleShowAllFiles -bool false; \ + killall Finder + +# Show items in desktop +defaults write com.apple.finder CreateDesktop -bool true; \ + killall Finder + +# Hide items in desktop +defaults write com.apple.finder CreateDesktop -bool false; \ + killall Finder diff --git a/navi b/navi index f5d8af9..24e06b4 100755 --- a/navi +++ b/navi @@ -1,9 +1,9 @@ #!/usr/bin/env bash set -euo pipefail -export SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +export NAVI_HOME="$(cd "$(dirname "$0")" && pwd)" -source "${SCRIPT_DIR}/src/main.sh" +source "${NAVI_HOME}/src/main.sh" ##? An interactive cheatsheet tool for the command-line ##? @@ -37,7 +37,7 @@ source "${SCRIPT_DIR}/src/main.sh" ##? full docs ##? Please refer to the README at https://github.com/denisidoro/navi -VERSION="0.12.0" +VERSION="0.13.0" NAVI_ENV="${NAVI_ENV:-prod}" opts::eval "$@" diff --git a/navi.plugin.bash b/navi.plugin.bash index 64e3d4d..5ee3757 100644 --- a/navi.plugin.bash +++ b/navi.plugin.bash @@ -1,3 +1,3 @@ #!/usr/bin/env bash -bind '"\C-g": " \C-u \C-a\C-k`printf \"\\e\" && navi --print`\e\C-e\C-y\C-a\C-d\C-y\ey\C-h\C-e\C-b"' +bind '"\C-g": " \C-u \C-a\C-k`printf \"\\e\" && NAVI_USE_FZF_ALL_INPUTS=true navi --print`\e\C-e\C-y\C-a\C-d\C-y\ey\C-h\C-e\C-b"' diff --git a/navi.plugin.fish b/navi.plugin.fish new file mode 100644 index 0000000..d206bb9 --- /dev/null +++ b/navi.plugin.fish @@ -0,0 +1,21 @@ +function navi-widget -d 'Call navi' + set -q NAVI_USE_FZF_ALL_INPUTS; or set -l NAVI_USE_FZF_ALL_INPUTS "true" + begin + navi --print | while read -l r; set result $result $r; end + + if [ -n "$result" ] + echo $result + + # Remove last token from commandline. + commandline -t "" + end + end + + # commandline -f repaint +end + +bind \cg navi-widget + +if bind -M insert > /dev/null 2>&1 + bind -M insert \cr navi-widget +end diff --git a/scripts/install b/scripts/install index 4aa75b6..e58b4b6 100755 --- a/scripts/install +++ b/scripts/install @@ -1,11 +1,11 @@ #!/usr/bin/env bash set -euo pipefail -export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" +export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)" script() { echo "#!/usr/bin/env bash" - echo "${SCRIPT_DIR}/navi" '"$@"' + echo "${NAVI_HOME}/navi" '"$@"' } folder="${1:-/usr/local/bin}" diff --git a/scripts/lint b/scripts/lint index 601c3ed..5952fca 100755 --- a/scripts/lint +++ b/scripts/lint @@ -3,13 +3,13 @@ set -euo pipefail # please refer to https://github.com/denisidoro/dotfiles/blob/master/scripts/code/beautify -export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" +export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)" files_to_lint() { find . -iname '*.sh' find scripts/* - echo "${SCRIPT_DIR}/test/run" - echo "${SCRIPT_DIR}/navi" + echo "${NAVI_HOME}/test/run" + echo "${NAVI_HOME}/navi" } for f in $(files_to_lint); do diff --git a/scripts/playground b/scripts/playground index 62b805f..5ca41bb 100755 --- a/scripts/playground +++ b/scripts/playground @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -euo pipefail -export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" -export NAVI_PATH="${SCRIPT_DIR}/test:${SCRIPT_DIR}/cheats" +export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)" +export NAVI_PATH="${NAVI_HOME}/test:${NAVI_HOME}/cheats" -"${SCRIPT_DIR}/navi" "$@" \ No newline at end of file +"${NAVI_HOME}/navi" "$@" \ No newline at end of file diff --git a/scripts/release b/scripts/release index f07eaad..d82a0dc 100755 --- a/scripts/release +++ b/scripts/release @@ -1,8 +1,8 @@ #!/usr/bin/env bash set -euo pipefail -export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" -source "${SCRIPT_DIR}/src/main.sh" +export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)" +source "${NAVI_HOME}/src/main.sh" sha256() { if command_exists sha256sum; then @@ -22,12 +22,12 @@ header() { echo } -cd "$SCRIPT_DIR" +cd "$NAVI_HOME" header "git pull" git pull -version="$(grep VERSION "${SCRIPT_DIR}/navi" | grep -Eo '[0-9\.]+')" +version="$(grep VERSION "${NAVI_HOME}/navi" | grep -Eo '[0-9\.]+')" tag="v${version}" tar="https://github.com/denisidoro/navi/archive/${tag}.tar.gz" formula="/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/navi.rb" diff --git a/scripts/update b/scripts/update index 7ae0e59..a448a42 100755 --- a/scripts/update +++ b/scripts/update @@ -1,9 +1,9 @@ #!/usr/bin/env bash set -euo pipefail -export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" +export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)" -cd "$SCRIPT_DIR" +cd "$NAVI_HOME" git pull -"${SCRIPT_DIR}/scripts/install" || true +"${NAVI_HOME}/scripts/install" || true diff --git a/src/main.sh b/src/main.sh index dfc9576..26a481e 100644 --- a/src/main.sh +++ b/src/main.sh @@ -4,18 +4,18 @@ if ${NAVI_FORCE_GNU:-false} && [ -n "${DOTFILES:-}" ]; then source "${DOTFILES}/scripts/core/main.sh" fi -source "${SCRIPT_DIR}/src/arg.sh" -source "${SCRIPT_DIR}/src/cheat.sh" -source "${SCRIPT_DIR}/src/cmd.sh" -source "${SCRIPT_DIR}/src/coll.sh" -source "${SCRIPT_DIR}/src/dict.sh" -source "${SCRIPT_DIR}/src/health.sh" -source "${SCRIPT_DIR}/src/misc.sh" -source "${SCRIPT_DIR}/src/opts.sh" -source "${SCRIPT_DIR}/src/search.sh" -source "${SCRIPT_DIR}/src/selection.sh" -source "${SCRIPT_DIR}/src/str.sh" -source "${SCRIPT_DIR}/src/ui.sh" +source "${NAVI_HOME}/src/arg.sh" +source "${NAVI_HOME}/src/cheat.sh" +source "${NAVI_HOME}/src/cmd.sh" +source "${NAVI_HOME}/src/coll.sh" +source "${NAVI_HOME}/src/dict.sh" +source "${NAVI_HOME}/src/health.sh" +source "${NAVI_HOME}/src/misc.sh" +source "${NAVI_HOME}/src/opts.sh" +source "${NAVI_HOME}/src/search.sh" +source "${NAVI_HOME}/src/selection.sh" +source "${NAVI_HOME}/src/str.sh" +source "${NAVI_HOME}/src/ui.sh" handler::main() { local -r cheats="$(cheat::memoized_read_all)" @@ -66,18 +66,22 @@ handler::version() { echo "${VERSION:-unknown}" if $full; then - source "${SCRIPT_DIR}/src/version.sh" + source "${NAVI_HOME}/src/version.sh" version::code 2>/dev/null \ || die "unknown code" fi } handler::script() { - "${SCRIPT_DIR}/scripts/${SCRIPT_ARGS[@]}" + "${NAVI_HOME}/scripts/"${SCRIPT_ARGS[@]} +} + +handler::fn() { + ${SCRIPT_ARGS[@]} } handler::home() { - echo "${SCRIPT_DIR}" + echo "${NAVI_HOME}" } handler::widget() { @@ -85,8 +89,9 @@ handler::widget() { local -r print="$(dict::get "$OPTIONS" print)" case "$SH" in - zsh) widget="${SCRIPT_DIR}/navi.plugin.zsh" ;; - bash) widget="${SCRIPT_DIR}/navi.plugin.bash" ;; + zsh) widget="${NAVI_HOME}/navi.plugin.zsh" ;; + bash) widget="${NAVI_HOME}/navi.plugin.bash" ;; + fish) widget="${NAVI_HOME}/navi.plugin.fish" ;; *) die "Invalid shell: $SH" ;; esac @@ -124,6 +129,9 @@ main() { script) handler::script ;; + fn) + handler::fn + ;; help) handler::help ;; diff --git a/src/opts.sh b/src/opts.sh index ab9666c..2ae9034 100644 --- a/src/opts.sh +++ b/src/opts.sh @@ -12,7 +12,7 @@ opts::eval() { local print=false local interpolation=true local preview=true - local path="${NAVI_PATH:-${NAVI_DIR:-${SCRIPT_DIR}/cheats}}" + local path="${NAVI_PATH:-${NAVI_DIR:-${NAVI_HOME}/cheats}}" local autoselect=true local best=false local query="" @@ -28,6 +28,7 @@ opts::eval() { best|b) best=true; wait_for="best"; shift ;; home) entry_point="home"; shift ;; script) entry_point="script"; shift; SCRIPT_ARGS="$@" ;; + fn) entry_point="fn"; shift; SCRIPT_ARGS="$@" ;; widget) entry_point="widget"; shift; wait_for="widget" ;; esac diff --git a/src/ui.sh b/src/ui.sh index 98f61d6..3cc49a8 100644 --- a/src/ui.sh +++ b/src/ui.sh @@ -17,7 +17,7 @@ ui::fzf() { ui::select() { local -r cheats="$1" - local -r script_path="${SCRIPT_DIR}/navi" + local -r script_path="${NAVI_HOME}/navi" local -r preview_cmd="echo \'{}\' | $(arg::serialize_code) | xargs -I% \"${script_path}\" preview %" local -r query="$(dict::get "$OPTIONS" query)" diff --git a/src/version.sh b/src/version.sh index 6ec4c48..a830cd8 100644 --- a/src/version.sh +++ b/src/version.sh @@ -1,5 +1,5 @@ version::code() { - cd "$SCRIPT_DIR" + cd "$NAVI_HOME" local -r git_info=$(git log -n 1 --pretty=format:'%h%n%ad%n%s' --date=format:'%Y-%m-%d %Hh%M') if [ -z "$git_info" ]; then return 1 diff --git a/test/core.sh b/test/core.sh index bf7d348..6d1f00a 100644 --- a/test/core.sh +++ b/test/core.sh @@ -2,11 +2,11 @@ export NAVI_FORCE_GNU=true -source "${SCRIPT_DIR}/src/main.sh" -source "${SCRIPT_DIR}/test/log.sh" +source "${NAVI_HOME}/src/main.sh" +source "${NAVI_HOME}/test/log.sh" opts::eval "$@" -TEST_DIR="${SCRIPT_DIR}/test" +TEST_DIR="${NAVI_HOME}/test" PASSED=0 FAILED=0 diff --git a/test/integration_test.sh b/test/integration_test.sh index fd5ba98..36cf735 100644 --- a/test/integration_test.sh +++ b/test/integration_test.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -NAVI_BIN="${SCRIPT_DIR}/navi" -TEST_DIR="${SCRIPT_DIR}/test" +NAVI_BIN="${NAVI_HOME}/navi" +TEST_DIR="${NAVI_HOME}/test" _navi() { "$NAVI_BIN" "$@" diff --git a/test/run b/test/run index 14f5a84..661be7a 100755 --- a/test/run +++ b/test/run @@ -1,10 +1,10 @@ #!/usr/bin/env bash set -euo pipefail -export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" -source "${SCRIPT_DIR}/test/core.sh" +export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)" +source "${NAVI_HOME}/test/core.sh" -tests="$(find "$SCRIPT_DIR/test" -iname "${1:-}*_test.sh")" +tests="$(find "$NAVI_HOME/test" -iname "${1:-}*_test.sh")" for test in $tests; do source "$test"