Minor changes (#122)

This commit is contained in:
Denis Isidoro 2019-10-11 14:33:16 -03:00 committed by GitHub
parent 40ed4e60ba
commit 69e74204b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 158 additions and 56 deletions

View File

@ -50,13 +50,20 @@ brew install denisidoro/tools/navi
### Using git ### Using git
Alternatively, you can `git clone` this repository and run `make`: Alternatively, you can `git clone` this repository:
```sh ```sh
git clone --depth 1 https://github.com/denisidoro/navi /opt/navi git clone --depth 1 https://github.com/denisidoro/navi /opt/navi
cd /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 ### Using oh-my-zsh
@ -76,7 +83,7 @@ plugins=(docker tmux fzf navi)
Finally, you can use it as a [shell widget](#shell-widget). 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 Upgrading
--------- ---------

27
cheats/android.cheat Normal file
View File

@ -0,0 +1,27 @@
% android, device
# Get property
adb -s <device> shell getprop <property>
# Install APK
adb -s <device> install -r <path>
# Uninstall package
adb -s <device> uninstall -r <package>
# Clear user data for package
adb -s <device> shell pm clear <package>
# Dispatch a deep-link / open URI
adb -s <device> shell am start <uri>
$ device: adb devices --- --headers 1 --column 1
% android, emulator
# Start emulator
"$ANDROID_HOME/tools/emulator" -avd <emulator> -netdelay none -netspeed full
$ emulator: "$ANDROID_HOME/tools/emulator" -list-avds

View File

@ -1,4 +0,0 @@
% awk, string
# Print last column
awk '{print $NF}'

View File

@ -74,6 +74,10 @@ git clean -dxf
git rebase master -S -f git rebase master -S -f
# See all open pull requests of a user on Github # See all open pull requests of a user on Github
url::open 'https://github.com/pulls?&q=author:<user>+is:open+is:pr' navi fn url::open 'https://github.com/pulls?&q=author:<user>+is:open+is:pr'
# Checkout a branch from a fork
git fetch origin pull/<pr_number>/head:pr/<pr_number> \
&& git checkout pr/<pr_number>
$ branch: git branch | awk '{print $NF}' $ branch: git branch | awk '{print $NF}'

18
cheats/misc.cheat Normal file
View File

@ -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/<location>" \
| grep -v "New feature" \
| grep -v Follow
% qr code
# Create a QR code with the content
echo <content> | curl -F-=\<- qrenco.de

20
cheats/osx.cheat Normal file
View File

@ -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

6
navi
View File

@ -1,9 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail 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 ##? An interactive cheatsheet tool for the command-line
##? ##?
@ -37,7 +37,7 @@ source "${SCRIPT_DIR}/src/main.sh"
##? full docs ##? full docs
##? Please refer to the README at https://github.com/denisidoro/navi ##? Please refer to the README at https://github.com/denisidoro/navi
VERSION="0.12.0" VERSION="0.13.0"
NAVI_ENV="${NAVI_ENV:-prod}" NAVI_ENV="${NAVI_ENV:-prod}"
opts::eval "$@" opts::eval "$@"

View File

@ -1,3 +1,3 @@
#!/usr/bin/env bash #!/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"'

21
navi.plugin.fish Normal file
View File

@ -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

View File

@ -1,11 +1,11 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)"
script() { script() {
echo "#!/usr/bin/env bash" echo "#!/usr/bin/env bash"
echo "${SCRIPT_DIR}/navi" '"$@"' echo "${NAVI_HOME}/navi" '"$@"'
} }
folder="${1:-/usr/local/bin}" folder="${1:-/usr/local/bin}"

View File

@ -3,13 +3,13 @@ set -euo pipefail
# please refer to https://github.com/denisidoro/dotfiles/blob/master/scripts/code/beautify # 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() { files_to_lint() {
find . -iname '*.sh' find . -iname '*.sh'
find scripts/* find scripts/*
echo "${SCRIPT_DIR}/test/run" echo "${NAVI_HOME}/test/run"
echo "${SCRIPT_DIR}/navi" echo "${NAVI_HOME}/navi"
} }
for f in $(files_to_lint); do for f in $(files_to_lint); do

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)"
export NAVI_PATH="${SCRIPT_DIR}/test:${SCRIPT_DIR}/cheats" export NAVI_PATH="${NAVI_HOME}/test:${NAVI_HOME}/cheats"
"${SCRIPT_DIR}/navi" "$@" "${NAVI_HOME}/navi" "$@"

View File

@ -1,8 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail 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"
sha256() { sha256() {
if command_exists sha256sum; then if command_exists sha256sum; then
@ -22,12 +22,12 @@ header() {
echo echo
} }
cd "$SCRIPT_DIR" cd "$NAVI_HOME"
header "git pull" header "git pull"
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}" tag="v${version}"
tar="https://github.com/denisidoro/navi/archive/${tag}.tar.gz" tar="https://github.com/denisidoro/navi/archive/${tag}.tar.gz"
formula="/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/navi.rb" formula="/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/navi.rb"

View File

@ -1,9 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail 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 git pull
"${SCRIPT_DIR}/scripts/install" || true "${NAVI_HOME}/scripts/install" || true

View File

@ -4,18 +4,18 @@ if ${NAVI_FORCE_GNU:-false} && [ -n "${DOTFILES:-}" ]; then
source "${DOTFILES}/scripts/core/main.sh" source "${DOTFILES}/scripts/core/main.sh"
fi fi
source "${SCRIPT_DIR}/src/arg.sh" source "${NAVI_HOME}/src/arg.sh"
source "${SCRIPT_DIR}/src/cheat.sh" source "${NAVI_HOME}/src/cheat.sh"
source "${SCRIPT_DIR}/src/cmd.sh" source "${NAVI_HOME}/src/cmd.sh"
source "${SCRIPT_DIR}/src/coll.sh" source "${NAVI_HOME}/src/coll.sh"
source "${SCRIPT_DIR}/src/dict.sh" source "${NAVI_HOME}/src/dict.sh"
source "${SCRIPT_DIR}/src/health.sh" source "${NAVI_HOME}/src/health.sh"
source "${SCRIPT_DIR}/src/misc.sh" source "${NAVI_HOME}/src/misc.sh"
source "${SCRIPT_DIR}/src/opts.sh" source "${NAVI_HOME}/src/opts.sh"
source "${SCRIPT_DIR}/src/search.sh" source "${NAVI_HOME}/src/search.sh"
source "${SCRIPT_DIR}/src/selection.sh" source "${NAVI_HOME}/src/selection.sh"
source "${SCRIPT_DIR}/src/str.sh" source "${NAVI_HOME}/src/str.sh"
source "${SCRIPT_DIR}/src/ui.sh" source "${NAVI_HOME}/src/ui.sh"
handler::main() { handler::main() {
local -r cheats="$(cheat::memoized_read_all)" local -r cheats="$(cheat::memoized_read_all)"
@ -66,18 +66,22 @@ handler::version() {
echo "${VERSION:-unknown}" echo "${VERSION:-unknown}"
if $full; then if $full; then
source "${SCRIPT_DIR}/src/version.sh" source "${NAVI_HOME}/src/version.sh"
version::code 2>/dev/null \ version::code 2>/dev/null \
|| die "unknown code" || die "unknown code"
fi fi
} }
handler::script() { handler::script() {
"${SCRIPT_DIR}/scripts/${SCRIPT_ARGS[@]}" "${NAVI_HOME}/scripts/"${SCRIPT_ARGS[@]}
}
handler::fn() {
${SCRIPT_ARGS[@]}
} }
handler::home() { handler::home() {
echo "${SCRIPT_DIR}" echo "${NAVI_HOME}"
} }
handler::widget() { handler::widget() {
@ -85,8 +89,9 @@ handler::widget() {
local -r print="$(dict::get "$OPTIONS" print)" local -r print="$(dict::get "$OPTIONS" print)"
case "$SH" in case "$SH" in
zsh) widget="${SCRIPT_DIR}/navi.plugin.zsh" ;; zsh) widget="${NAVI_HOME}/navi.plugin.zsh" ;;
bash) widget="${SCRIPT_DIR}/navi.plugin.bash" ;; bash) widget="${NAVI_HOME}/navi.plugin.bash" ;;
fish) widget="${NAVI_HOME}/navi.plugin.fish" ;;
*) die "Invalid shell: $SH" ;; *) die "Invalid shell: $SH" ;;
esac esac
@ -124,6 +129,9 @@ main() {
script) script)
handler::script handler::script
;; ;;
fn)
handler::fn
;;
help) help)
handler::help handler::help
;; ;;

View File

@ -12,7 +12,7 @@ opts::eval() {
local print=false local print=false
local interpolation=true local interpolation=true
local preview=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 autoselect=true
local best=false local best=false
local query="" local query=""
@ -28,6 +28,7 @@ opts::eval() {
best|b) best=true; wait_for="best"; shift ;; best|b) best=true; wait_for="best"; shift ;;
home) entry_point="home"; shift ;; home) entry_point="home"; shift ;;
script) entry_point="script"; shift; SCRIPT_ARGS="$@" ;; script) entry_point="script"; shift; SCRIPT_ARGS="$@" ;;
fn) entry_point="fn"; shift; SCRIPT_ARGS="$@" ;;
widget) entry_point="widget"; shift; wait_for="widget" ;; widget) entry_point="widget"; shift; wait_for="widget" ;;
esac esac

View File

@ -17,7 +17,7 @@ ui::fzf() {
ui::select() { ui::select() {
local -r cheats="$1" 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 preview_cmd="echo \'{}\' | $(arg::serialize_code) | xargs -I% \"${script_path}\" preview %"
local -r query="$(dict::get "$OPTIONS" query)" local -r query="$(dict::get "$OPTIONS" query)"

View File

@ -1,5 +1,5 @@
version::code() { 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') 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 if [ -z "$git_info" ]; then
return 1 return 1

View File

@ -2,11 +2,11 @@
export NAVI_FORCE_GNU=true export NAVI_FORCE_GNU=true
source "${SCRIPT_DIR}/src/main.sh" source "${NAVI_HOME}/src/main.sh"
source "${SCRIPT_DIR}/test/log.sh" source "${NAVI_HOME}/test/log.sh"
opts::eval "$@" opts::eval "$@"
TEST_DIR="${SCRIPT_DIR}/test" TEST_DIR="${NAVI_HOME}/test"
PASSED=0 PASSED=0
FAILED=0 FAILED=0

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
NAVI_BIN="${SCRIPT_DIR}/navi" NAVI_BIN="${NAVI_HOME}/navi"
TEST_DIR="${SCRIPT_DIR}/test" TEST_DIR="${NAVI_HOME}/test"
_navi() { _navi() {
"$NAVI_BIN" "$@" "$NAVI_BIN" "$@"

View File

@ -1,10 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)"
source "${SCRIPT_DIR}/test/core.sh" 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 for test in $tests; do
source "$test" source "$test"