瀏覽代碼

Support both fzf and fzy

master
Arun Prakash Jana 5 年之前
父節點
當前提交
885cfd4734
沒有發現已知的金鑰在資料庫的簽署中 GPG 金鑰 ID: A75979F35C080412
共有 6 個檔案被更改,包括 48 行新增25 行删除
  1. +4
    -4
      plugins/README.md
  2. +1
    -1
      plugins/fzcd
  3. +10
    -2
      plugins/fzhist
  4. +11
    -1
      plugins/fzopen
  5. +2
    -2
      plugins/launch
  6. +20
    -15
      plugins/pskill

+ 4
- 4
plugins/README.md 查看文件

@@ -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
- 1
plugins/fzcd 查看文件

@@ -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


+ 10
- 2
plugins/fzhist 查看文件

@@ -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


+ 11
- 1
plugins/fzopen 查看文件

@@ -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*)


+ 2
- 2
plugins/launch 查看文件

@@ -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


+ 20
- 15
plugins/pskill 查看文件

@@ -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 $?
}

if [ "$(is_cmd_exists sudo)" -eq "0" ]; then
sucmd=sudo
elif [ "$(is_cmd_exists doas)" -eq "0" ]; then
sucmd=doas
else
sucmd=: # noop
fi

printf "Enter process name ['defunct' for zombies]: "
read -r psname

# shellcheck disable=SC2009
if ! [ -z "$psname" ]; then
# shellcheck disable=SC2009
cmd="$(ps -ax | grep -iw "$psname" | fzy | sed -e 's/^[ \t]*//' | cut -d' ' -f1)"
if which sudo >/dev/null 2>&1; then
sucmd=sudo
elif which doas >/dev/null 2>&1; then
sucmd=doas
else
sucmd=: # noop
fi

if which fzf >/dev/null 2>&1; then
fuzzy=fzf
elif which fzy >/dev/null 2>&1; then
fuzzy=fzy
else
exit 1
fi

cmd="$(ps -ax | grep -iw "$psname" | "$fuzzy" | sed -e 's/^[ \t]*//' | cut -d' ' -f1)"
$sucmd kill -9 "$cmd"
fi

Loading…
取消
儲存