mirror of
https://github.com/denisidoro/navi
synced 2024-11-22 03:23:05 +00:00
Improve zsh widget (#92)
This commit is contained in:
parent
b9084c0439
commit
260966ba6c
6 changed files with 45 additions and 5 deletions
18
README.md
18
README.md
|
@ -21,6 +21,7 @@ Table of Contents
|
||||||
* [Preventing execution](#preventing-execution)
|
* [Preventing execution](#preventing-execution)
|
||||||
* [Pre-filtering](#pre-filtering)
|
* [Pre-filtering](#pre-filtering)
|
||||||
* [Searching online repositories](#searching-online-repositories)
|
* [Searching online repositories](#searching-online-repositories)
|
||||||
|
* [Shell widget](#shell-widget)
|
||||||
* [More options](#more-options)
|
* [More options](#more-options)
|
||||||
* [Trying out online](#trying-out-online)
|
* [Trying out online](#trying-out-online)
|
||||||
* [Motivation](#motivation)
|
* [Motivation](#motivation)
|
||||||
|
@ -84,6 +85,23 @@ If you run `navi search <cmd>`, **navi** will try to download cheatsheets from o
|
||||||
|
|
||||||
Please note that these cheatsheets aren't curated by **navi**'s maintainers and should be taken with a grain of salt. If you're not sure about executing these snippets, make sure to check the preview window or use the `--print` option.
|
Please note that these cheatsheets aren't curated by **navi**'s maintainers and should be taken with a grain of salt. If you're not sure about executing these snippets, make sure to check the preview window or use the `--print` option.
|
||||||
|
|
||||||
|
### Shell widget
|
||||||
|
|
||||||
|
You can use **navi** as a widget to your shell:
|
||||||
|
![Widget](https://user-images.githubusercontent.com/3226564/65788699-03361080-e132-11e9-9e93-b2a4bc405bed.gif)
|
||||||
|
|
||||||
|
This way, your history is correctly populated and you can edit the command as you wish before executing it.
|
||||||
|
|
||||||
|
Right now, there's only a widget for zsh. If you want for other shells, please upvote [this issue](https://github.com/denisidoro/navi/issues/37).
|
||||||
|
|
||||||
|
In order to use it, add this line to your `.zshrc`-like file:
|
||||||
|
```sh
|
||||||
|
source "$(navi widget zsh)"
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, simply hit `Alt+G`.
|
||||||
|
|
||||||
|
|
||||||
### More options
|
### More options
|
||||||
|
|
||||||
Please refer to `navi --help` for more details.
|
Please refer to `navi --help` for more details.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
% awk, string
|
% awk, string
|
||||||
|
|
||||||
# Print last column
|
# Print last column
|
||||||
echo "1 2 3" | awk '{print $NF}'
|
awk '{print $NF}'
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
_call_navi() {
|
_call_navi() {
|
||||||
# zle kill-whole-line
|
local buff="$BUFFER"
|
||||||
zle -U "$(NAVI_FZF_ALL_INPUTS=true navi --print "$(echo "$CUTBUFFER" | xargs)" <> /dev/tty)"
|
zle kill-whole-line
|
||||||
zle accept-line
|
local cmd="$(NAVI_USE_FZF_ALL_INPUTS=true navi --print <> /dev/tty)"
|
||||||
|
zle -U "$buff$(echo "$cmd")"
|
||||||
|
# zle accept-line
|
||||||
}
|
}
|
||||||
|
|
||||||
zle -N _call_navi
|
zle -N _call_navi
|
||||||
|
|
|
@ -60,7 +60,7 @@ arg::pick() {
|
||||||
if [ -n "$suggestions" ]; then
|
if [ -n "$suggestions" ]; then
|
||||||
echo "$suggestions" | ui::pick --prompt "$arg: " --header-lines "${headers:-0}" | str::column "${column:-}"
|
echo "$suggestions" | ui::pick --prompt "$arg: " --header-lines "${headers:-0}" | str::column "${column:-}"
|
||||||
fi
|
fi
|
||||||
elif ${NAVI_FZF_ALL_INPUTS:-false}; then
|
elif ${NAVI_USE_FZF_ALL_INPUTS:-false}; then
|
||||||
echo "" | ui::pick --prompt "$arg: " --print-query --height 1
|
echo "" | ui::pick --prompt "$arg: " --print-query --height 1
|
||||||
else
|
else
|
||||||
printf "\033[0;36m${arg}:\033[0;0m " > /dev/tty
|
printf "\033[0;36m${arg}:\033[0;0m " > /dev/tty
|
||||||
|
|
18
src/main.sh
18
src/main.sh
|
@ -89,6 +89,21 @@ handler::home() {
|
||||||
echo "${SCRIPT_DIR}"
|
echo "${SCRIPT_DIR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handler::widget() {
|
||||||
|
local widget
|
||||||
|
|
||||||
|
case "$SH" in
|
||||||
|
zsh) widget="${SCRIPT_DIR}/shell/widget.zsh" ;;
|
||||||
|
*) echoerr "Invalid shell: $SH"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if "$(dict::get "$OPTIONS" print)"; then
|
||||||
|
cat "$widget"
|
||||||
|
else
|
||||||
|
echo "$widget"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
case "$(dict::get "$OPTIONS" entry_point)" in
|
case "$(dict::get "$OPTIONS" entry_point)" in
|
||||||
preview)
|
preview)
|
||||||
|
@ -117,6 +132,9 @@ main() {
|
||||||
help)
|
help)
|
||||||
handler::help
|
handler::help
|
||||||
;;
|
;;
|
||||||
|
widget)
|
||||||
|
handler::widget
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
health::fzf
|
health::fzf
|
||||||
handler::main
|
handler::main
|
||||||
|
|
|
@ -27,6 +27,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="$@" ;;
|
||||||
|
widget) entry_point="widget"; shift; wait_for="widget" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
|
@ -35,6 +36,7 @@ opts::eval() {
|
||||||
preview) query="$(arg::deserialize "$arg")"; wait_for="" ;;
|
preview) query="$(arg::deserialize "$arg")"; wait_for="" ;;
|
||||||
search) query="$arg"; wait_for=""; path="${path}:$(search::full_path "$query")"; ;;
|
search) query="$arg"; wait_for=""; path="${path}:$(search::full_path "$query")"; ;;
|
||||||
query|best) query="$arg"; wait_for="" ;;
|
query|best) query="$arg"; wait_for="" ;;
|
||||||
|
widget) SH="$arg"; wait_for="" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case $arg in
|
case $arg in
|
||||||
|
|
Loading…
Reference in a new issue