mirror of
https://github.com/denisidoro/navi
synced 2024-11-21 19:13:07 +00:00
parent
8f2bc5f7e7
commit
a70c6dfadd
3 changed files with 52 additions and 10 deletions
23
README.md
23
README.md
|
@ -32,7 +32,9 @@ Table of contents
|
|||
* [Cheatsheet syntax](#cheatsheet-syntax)
|
||||
* [Syntax overview](#syntax-overview)
|
||||
* [Variables](#variables)
|
||||
* [Table formatting](#table-formatting)
|
||||
* [Variable options](#variable-options)
|
||||
* [Table formatting](#table-formatting)
|
||||
* [Multiple choice](#multiple-choice)
|
||||
* [List customization](#list-customization)
|
||||
* [Related projects](#related-projects)
|
||||
* [Etymology](#etymology)
|
||||
|
@ -233,9 +235,13 @@ $ x: echo -e '1\n2\n3'
|
|||
$ y: echo -e "$((x+10))\n$((x+20))"
|
||||
```
|
||||
|
||||
### Table formatting
|
||||
### Variable options
|
||||
|
||||
You can pick a specific column of a selection and set the number of lines considered as headers:
|
||||
For lines starting with `$` you can add extra options using `---`.
|
||||
|
||||
#### Table formatting
|
||||
|
||||
You can pick a specific column of a selection and set the number of lines considered as headers via `--column` and `--headers`:
|
||||
|
||||
```sh
|
||||
# This will pick the 3rd column and use the first line as header
|
||||
|
@ -244,6 +250,17 @@ docker rmi <image_id>
|
|||
$ image_id: docker images --- --column 3 --headers 1
|
||||
```
|
||||
|
||||
#### Multiple choice
|
||||
|
||||
You can select multiple values via `--multi` and hitting `<TAB>`:
|
||||
|
||||
```sh
|
||||
# The resulting command will be something like: cat "a.txt" "b.txt"
|
||||
cat <files>
|
||||
|
||||
$ files: ls --- --multi true
|
||||
```
|
||||
|
||||
List customization
|
||||
------------------
|
||||
|
||||
|
|
2
navi
2
navi
|
@ -4,7 +4,7 @@ set -euo pipefail
|
|||
export NAVI_HOME="$(cd "$(dirname "$0")" && pwd)"
|
||||
source "${NAVI_HOME}/src/main.sh"
|
||||
|
||||
VERSION="0.17.1"
|
||||
VERSION="0.18.0"
|
||||
NAVI_ENV="${NAVI_ENV:-prod}"
|
||||
|
||||
opts::eval "$@"
|
||||
|
|
37
src/arg.sh
37
src/arg.sh
|
@ -19,14 +19,28 @@ arg::escape() {
|
|||
|
||||
arg::interpolate() {
|
||||
local -r arg="$1"
|
||||
local -r value="$2"
|
||||
local -r value="$(echo "$2" | tr "$ESCAPE_CHAR_3" '\n')"
|
||||
|
||||
local -r words="$(echo "$value" | wc -w | xargs)"
|
||||
local -r lines="$(echo "$value" | wc -l)"
|
||||
|
||||
if [ $lines -lt 2 ]; then
|
||||
|
||||
local -r words="$(echo "$value" | wc -w | xargs)"
|
||||
|
||||
if [[ $words > 1 ]]; then
|
||||
sed "s|<${arg}>|\"${value}\"|g"
|
||||
else
|
||||
sed "s|<${arg}>|${value}|g"
|
||||
fi
|
||||
|
||||
if [[ $words > 1 ]]; then
|
||||
sed "s|<${arg}>|\"${value}\"|g"
|
||||
else
|
||||
sed "s|<${arg}>|${value}|g"
|
||||
|
||||
local -r newvalue="$(echo "$value" \
|
||||
| xargs -I% echo '"%"' \
|
||||
| tr '\n' ' ')"
|
||||
|
||||
sed "s|<${arg}>|${newvalue}|g"
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -78,8 +92,19 @@ arg::pick() {
|
|||
|
||||
if [ -n "$fn" ]; then
|
||||
local suggestions="$(eval "$fn" 2>/dev/null)"
|
||||
|
||||
local args
|
||||
args+=("--prompt"); args+=("${arg}: ")
|
||||
args+=("--header-lines"); args+=("${headers:-0}")
|
||||
if ${multi:-false}; then
|
||||
args+=("-m")
|
||||
fi
|
||||
|
||||
if [ -n "$suggestions" ]; then
|
||||
echo "$suggestions" | ui::fzf --prompt "$arg: " --header-lines "${headers:-0}" | str::column "${column:-}" "${separator:-}"
|
||||
echo "$suggestions" \
|
||||
| ui::fzf ${args[@]:-} \
|
||||
| str::column "${column:-}" "${separator:-}" \
|
||||
| tr '\n' "$ESCAPE_CHAR_3"
|
||||
fi
|
||||
elif ${NAVI_USE_FZF_ALL_INPUTS:-false}; then
|
||||
echo "" | ui::fzf --prompt "$arg: " --print-query --no-select-1 --height 1
|
||||
|
|
Loading…
Reference in a new issue