mirror of
https://github.com/denisidoro/navi
synced 2024-11-10 22:14:15 +00:00
parent
9dce96a871
commit
beab843c1e
3 changed files with 42 additions and 15 deletions
21
scripts/lint
21
scripts/lint
|
@ -1,13 +1,18 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
|
||||
# please refer to https://github.com/denisidoro/dotfiles/blob/master/scripts/code/beautify
|
||||
|
||||
cd "${SCRIPT_DIR}"
|
||||
find . -iname '*.sh' | xargs -I% dot code beautify %
|
||||
find scripts/* | xargs -I% dot code beautify %
|
||||
find shell/* | xargs -I% dot code beautify %
|
||||
dot code beautify "${SCRIPT_DIR}/test/run"
|
||||
dot code beautify "${SCRIPT_DIR}/navi"
|
||||
export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
|
||||
files_to_lint() {
|
||||
find . -iname '*.sh'
|
||||
find scripts/*
|
||||
find shell/*
|
||||
echo "${SCRIPT_DIR}/test/run"
|
||||
echo "${SCRIPT_DIR}/navi"
|
||||
}
|
||||
|
||||
for f in $(files_to_lint); do
|
||||
dot code beautify "$f"
|
||||
done
|
||||
|
|
17
src/opts.sh
17
src/opts.sh
|
@ -14,6 +14,8 @@ opts::eval() {
|
|||
local preview=true
|
||||
local path="${NAVI_PATH:-${NAVI_DIR:-${SCRIPT_DIR}/cheats}}"
|
||||
local autoselect=true
|
||||
local best=false
|
||||
local query=""
|
||||
|
||||
case "${1:-}" in
|
||||
--version|version) entry_point="version"; shift ;;
|
||||
|
@ -22,6 +24,7 @@ opts::eval() {
|
|||
search) entry_point="search"; wait_for="search"; shift ;;
|
||||
preview) entry_point="preview"; wait_for="preview"; shift ;;
|
||||
query|q) wait_for="query"; shift ;;
|
||||
best|b) best=true; wait_for="best"; shift ;;
|
||||
home) entry_point="home"; shift ;;
|
||||
script) entry_point="script"; shift; SCRIPT_ARGS="$@" ;;
|
||||
esac
|
||||
|
@ -31,7 +34,7 @@ opts::eval() {
|
|||
path) path="$arg"; wait_for="" ;;
|
||||
preview) query="$(arg::deserialize "$arg")"; wait_for="" ;;
|
||||
search) query="$arg"; wait_for=""; path="${path}:$(search::full_path "$query")"; ;;
|
||||
query) query="$arg"; wait_for="" ;;
|
||||
query|best) query="$arg"; wait_for="" ;;
|
||||
esac
|
||||
|
||||
case $arg in
|
||||
|
@ -39,11 +42,19 @@ opts::eval() {
|
|||
--no-interpolation) interpolation=false ;;
|
||||
--command-for) wait_for="command-for" ;;
|
||||
--no-preview) preview=false ;;
|
||||
--path) wait_for="path" ;;
|
||||
--path|--dir) wait_for="path" ;;
|
||||
--no-autoselect) autoselect=false ;;
|
||||
esac
|
||||
done
|
||||
|
||||
OPTIONS="$(dict::new entry_point "$entry_point" print "$print" interpolation "$interpolation" preview "$preview" autoselect "$autoselect" query "${query:-}")"
|
||||
OPTIONS="$(dict::new \
|
||||
entry_point "$entry_point" \
|
||||
print "$print" \
|
||||
interpolation "$interpolation" \
|
||||
preview "$preview" \
|
||||
autoselect "$autoselect" \
|
||||
query "$query" \
|
||||
best "$best")"
|
||||
|
||||
export NAVI_PATH="$path"
|
||||
}
|
||||
|
|
19
src/ui.sh
19
src/ui.sh
|
@ -23,6 +23,7 @@ ui::select() {
|
|||
local -r query="$(dict::get "$OPTIONS" query)"
|
||||
local -r entry_point="$(dict::get "$OPTIONS" entry_point)"
|
||||
local -r preview="$(dict::get "$OPTIONS" preview)"
|
||||
local -r best="$(dict::get "$OPTIONS" best)"
|
||||
|
||||
local args=()
|
||||
args+=("-i")
|
||||
|
@ -31,17 +32,27 @@ ui::select() {
|
|||
args+=("--preview"); args+=("$preview_cmd")
|
||||
args+=("--preview-window"); args+=("up:1")
|
||||
fi
|
||||
if [ -n "$query" ]; then
|
||||
args+=("--query=${query} ")
|
||||
if [[ -n "$query" ]] && $best; then
|
||||
args+=("--filter"); args+=("${query} ")
|
||||
elif [[ -n "$query" ]] && ! $best; then
|
||||
args+=("--query"); args+=("${query} ")
|
||||
fi
|
||||
if [ "$entry_point" = "search" ]; then
|
||||
args+=("--header")
|
||||
args+=("Displaying online results. Please refer to 'navi --help' for details")
|
||||
args+=("--header"); args+=("Displaying online results. Please refer to 'navi --help' for details")
|
||||
fi
|
||||
|
||||
ui::_select_post() {
|
||||
if $best; then
|
||||
head -n1
|
||||
else
|
||||
cat
|
||||
fi
|
||||
}
|
||||
|
||||
echo "$cheats" \
|
||||
| cheat::read_many \
|
||||
| ui::pick "${args[@]}" \
|
||||
| ui::_select_post \
|
||||
| selection::dict
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue