mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 03:41:27 +00:00
Support both fzf and fzy
This commit is contained in:
parent
9614fec13b
commit
885cfd4734
|
@ -20,9 +20,9 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina
|
|||
| diffs | Diff for selection (limited to 2 for directories) | sh | vimdiff |
|
||||
| dragdrop | Drag/drop files from/into nnn | sh | [dragon](https://github.com/mwh/dragon) |
|
||||
| exetoggle | Toggle executable status of hovered file | sh | chmod |
|
||||
| fzcd | Change to the directory of a fuzzy-selected file/dir | sh | fzf/fzy<br>(optional fd) |
|
||||
| fzhist | Fuzzy-select a cmd from history, edit in `$EDITOR` and run | sh | fzy |
|
||||
| fzopen | Fuzzy find a file in dir subtree and edit or open | sh | fzy, xdg-open |
|
||||
| fzcd | Change to the directory of a fuzzy-selected file/dir | sh | fzf/fzy<br>fd/fdfind/find |
|
||||
| fzhist | Fuzzy-select a cmd from history, edit in `$EDITOR` and run | sh | fzf/fzy |
|
||||
| fzopen | Fuzzy find a file in dir subtree and edit or open | sh | fzf/fzy, xdg-open |
|
||||
| getplugs | Update plugins | sh | curl |
|
||||
| gutenread | Browse, download, read from Project Gutenberg | sh | curl, unzip, w3m<br>[epr](https://github.com/wustho/epr) (optional) |
|
||||
| hexview | View a file in hex in `$PAGER` | sh | xxd |
|
||||
|
@ -46,7 +46,7 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina
|
|||
| pdfread | Read a PDF or text file aloud | sh | pdftotext, mpv,<br>pico2wave |
|
||||
| pdfview | View PDF file in `$PAGER` | sh | pdftotext/<br>mupdf-tools |
|
||||
| picker | Pick files and list one per line (to pipe) | sh | nnn |
|
||||
| pskill | Fuzzy list by name and kill process or zombie | sh | fzy, sudo/doas |
|
||||
| pskill | Fuzzy list by name and kill process or zombie | sh | fzf/fzy, ps,<br>sudo/doas |
|
||||
| renamer | Batch rename selection or files in dir | sh | [qmv](https://www.nongnu.org/renameutils/)/[vidir](https://joeyh.name/code/moreutils/) |
|
||||
| ringtone | Create a variable bitrate mp3 ringtone from file | sh | date, ffmpeg |
|
||||
| splitjoin | Split file or join selection | sh | split, cat |
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
# Description: Run fzf/fzy/fd/fdfind/find and go to the directory of the file selected
|
||||
# Description: Run fzf/fzy, fd/fdfind/find and go to the directory of the file selected
|
||||
#
|
||||
# Shell: POSIX compliant
|
||||
# Author: Anna Arad
|
||||
|
|
|
@ -6,14 +6,22 @@
|
|||
# Shell: POSIX compliant
|
||||
# Author: Arun Prakash Jana
|
||||
|
||||
if which fzf >/dev/null 2>&1; then
|
||||
fuzzy=fzf
|
||||
elif which fzy >/dev/null 2>&1; then
|
||||
fuzzy=fzy
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
shellname="$(basename "$SHELL")"
|
||||
|
||||
if [ "$shellname" = "bash" ]; then
|
||||
hist_file="$HOME/.bash_history"
|
||||
entry="$(fzy < "$hist_file")"
|
||||
entry="$("$fuzzy" < "$hist_file")"
|
||||
elif [ "$shellname" = "fish" ]; then
|
||||
hist_file="$HOME/.config/fish/fish_history"
|
||||
entry="$(grep "\- cmd: " "$hist_file" | cut -c 8- | fzy)"
|
||||
entry="$(grep "\- cmd: " "$hist_file" | cut -c 8- | "$fuzzy")"
|
||||
fi
|
||||
|
||||
if ! [ -z "$entry" ]; then
|
||||
|
|
|
@ -4,10 +4,20 @@
|
|||
# Opens in $VISUAL or $EDITOR if text
|
||||
# Opens other type of files with xdg-open
|
||||
#
|
||||
# Requires: fzf/fzy, xdg-open
|
||||
#
|
||||
# Shell: POSIX compliant
|
||||
# Author: Arun Prakash Jana
|
||||
|
||||
entry="$(find . -type f 2>/dev/null | fzy)"
|
||||
if which fzf >/dev/null 2>&1; then
|
||||
fuzzy=fzf
|
||||
elif which fzy >/dev/null 2>&1; then
|
||||
fuzzy=fzy
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
entry="$(find . -type f 2>/dev/null | "$fuzzy")"
|
||||
|
||||
case "$(file -biL "$entry")" in
|
||||
*text*)
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#
|
||||
# xfce4-terminal -e "${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/launch
|
||||
#
|
||||
# Requires: fzf or fzy
|
||||
# Requires: fzf/fzy
|
||||
#
|
||||
# Usage: launch [delay]
|
||||
# delay is in seconds, if omitted launch waits for 1 sec
|
||||
|
@ -25,7 +25,7 @@ IFS=':'
|
|||
|
||||
get_selection() {
|
||||
if which fzf >/dev/null 2>&1; then
|
||||
{ IFS=':'; ls -H $PATH; } | sort | fzy
|
||||
{ IFS=':'; ls -H $PATH; } | sort | fzf
|
||||
elif which fzy >/dev/null 2>&1; then
|
||||
{ IFS=':'; ls -H $PATH; } | sort | fzy
|
||||
else
|
||||
|
|
|
@ -2,29 +2,34 @@
|
|||
|
||||
# Description: Fuzzy list and kill a (zombie) process by name
|
||||
#
|
||||
# Requires: fzf or fzy, ps
|
||||
#
|
||||
# Note: To kill a zombie process enter "zombie"
|
||||
#
|
||||
# Shell: POSIX compliant
|
||||
# Author: Arun Prakash Jana
|
||||
|
||||
is_cmd_exists () {
|
||||
which "$1" > /dev/null 2>&1
|
||||
echo $?
|
||||
}
|
||||
printf "Enter process name ['defunct' for zombies]: "
|
||||
read -r psname
|
||||
|
||||
if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
|
||||
# shellcheck disable=SC2009
|
||||
if ! [ -z "$psname" ]; then
|
||||
if which sudo >/dev/null 2>&1; then
|
||||
sucmd=sudo
|
||||
elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
|
||||
elif which doas >/dev/null 2>&1; then
|
||||
sucmd=doas
|
||||
else
|
||||
sucmd=: # noop
|
||||
fi
|
||||
|
||||
printf "Enter process name ['defunct' for zombies]: "
|
||||
read -r psname
|
||||
if which fzf >/dev/null 2>&1; then
|
||||
fuzzy=fzf
|
||||
elif which fzy >/dev/null 2>&1; then
|
||||
fuzzy=fzy
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! [ -z "$psname" ]; then
|
||||
# shellcheck disable=SC2009
|
||||
cmd="$(ps -ax | grep -iw "$psname" | fzy | sed -e 's/^[ \t]*//' | cut -d' ' -f1)"
|
||||
cmd="$(ps -ax | grep -iw "$psname" | "$fuzzy" | sed -e 's/^[ \t]*//' | cut -d' ' -f1)"
|
||||
$sucmd kill -9 "$cmd"
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue