Skip to content

Commit

Permalink
Minor changes (denisidoro#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
denisidoro authored Oct 11, 2019
1 parent 40ed4e6 commit 69e7420
Show file tree
Hide file tree
Showing 21 changed files with 158 additions and 56 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
---------
Expand Down
27 changes: 27 additions & 0 deletions cheats/android.cheat
Original file line number Diff line number Diff line change
@@ -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
4 changes: 0 additions & 4 deletions cheats/awk.cheat

This file was deleted.

6 changes: 5 additions & 1 deletion cheats/git.cheat
Original file line number Diff line number Diff line change
Expand Up @@ -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:<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}'
18 changes: 18 additions & 0 deletions cheats/misc.cheat
Original file line number Diff line number Diff line change
@@ -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 changes: 20 additions & 0 deletions cheats/osx.cheat
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 3 deletions navi
Original file line number Diff line number Diff line change
@@ -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
##?
Expand Down Expand Up @@ -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 "$@"
Expand Down
2 changes: 1 addition & 1 deletion navi.plugin.bash
Original file line number Diff line number Diff line change
@@ -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"'
21 changes: 21 additions & 0 deletions navi.plugin.fish
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions scripts/install
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down
6 changes: 3 additions & 3 deletions scripts/lint
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions scripts/playground
Original file line number Diff line number Diff line change
@@ -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" "$@"
"${NAVI_HOME}/navi" "$@"
8 changes: 4 additions & 4 deletions scripts/release
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions scripts/update
Original file line number Diff line number Diff line change
@@ -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
42 changes: 25 additions & 17 deletions src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -66,27 +66,32 @@ 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() {
local 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

Expand Down Expand Up @@ -124,6 +129,9 @@ main() {
script)
handler::script
;;
fn)
handler::fn
;;
help)
handler::help
;;
Expand Down
3 changes: 2 additions & 1 deletion src/opts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/ui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
2 changes: 1 addition & 1 deletion src/version.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/integration_test.sh
Original file line number Diff line number Diff line change
@@ -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" "$@"
Expand Down
Loading

0 comments on commit 69e7420

Please sign in to comment.