Improve integration for TUI file managers

This commit is contained in:
FollieHiyuki 2021-03-18 06:55:00 +03:00
parent dcd525c8bb
commit c50d0a100e
No known key found for this signature in database
GPG Key ID: 813CF484F4993419
15 changed files with 309 additions and 17 deletions

View File

@ -31,7 +31,7 @@
- **Launchers:** [nwg-launchers](https://github.com/nwg-piotr/nwg-launchers) / [wofi](https://hg.sr.ht/~scoopta/wofi) / [bemenu](https://github.com/Cloudef/bemenu), [rofi](https://github.com/davatorium/rofi) / [dmenu](https://git.disroot.org/FollieHiyuki/dmenu) - **Launchers:** [nwg-launchers](https://github.com/nwg-piotr/nwg-launchers) / [wofi](https://hg.sr.ht/~scoopta/wofi) / [bemenu](https://github.com/Cloudef/bemenu), [rofi](https://github.com/davatorium/rofi) / [dmenu](https://git.disroot.org/FollieHiyuki/dmenu)
- **Status bar:** [polybar](https://github.com/polybar/polybar), [waybar](https://github.com/Alexays/Waybar) - **Status bar:** [polybar](https://github.com/polybar/polybar), [waybar](https://github.com/Alexays/Waybar)
- **Terminal**: [alacritty](https://github.com/alacritty/alacritty), [foot](https://codeberg.org/dnkl/foot) - **Terminal**: [alacritty](https://github.com/alacritty/alacritty), [foot](https://codeberg.org/dnkl/foot)
- **File manager:** [ranger](https://github.com/ranger/ranger), [vifm](https://github.com/vifm/vifm) - **File manager:** [ranger](https://github.com/ranger/ranger), [vifm](https://github.com/vifm/vifm), [nnn](https://github.com/jarun/nnn)
- **Web browser:** [qutebrowser](https://github.com/qutebrowser/qutebrowser) - **Web browser:** [qutebrowser](https://github.com/qutebrowser/qutebrowser)
- **Image viewer:** [feh](https://github.com/derf/feh), [imv](https://github.com/eXeC64/imv) / [pqiv](https://github.com/phillipberndt/pqiv) - **Image viewer:** [feh](https://github.com/derf/feh), [imv](https://github.com/eXeC64/imv) / [pqiv](https://github.com/phillipberndt/pqiv)
- **Wayland wallpaper setter:** [swaybg](https://github.com/swaywm/swaybg) / [oguri](https://github.com/vilhalmer/oguri) / [mpvpaper](https://github.com/GhostNaN/mpvpaper) - **Wayland wallpaper setter:** [swaybg](https://github.com/swaywm/swaybg) / [oguri](https://github.com/vilhalmer/oguri) / [mpvpaper](https://github.com/GhostNaN/mpvpaper)

View File

@ -522,7 +522,7 @@ basherpacks_update() {
# nnn with cd on quit # nnn with cd on quit
if command -v nnn >/dev/null; then if command -v nnn >/dev/null; then
alias nnn="nnn -Hc" alias nnn="nnn -Hdcx"
alias ncp="cat ${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} | tr '\0' '\n'" alias ncp="cat ${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} | tr '\0' '\n'"
n () { n () {

View File

@ -44,7 +44,7 @@ abbr youbest 'youtube-dl -f bestvideo+bestaudio'
abbr youlist 'youtube-dl -f bestvideo+bestaudio --yes-playlist' abbr youlist 'youtube-dl -f bestvideo+bestaudio --yes-playlist'
# nnn # nnn
if command -v nnn >/dev/null if command -v nnn >/dev/null
abbr nnn 'nnn -Hc' abbr nnn 'nnn -Hdcx'
alias ncp="cat $XDG_CONFIG_HOME/nnn/.selection | tr '\0' '\n'" alias ncp="cat $XDG_CONFIG_HOME/nnn/.selection | tr '\0' '\n'"
function n --wraps nnn --description 'support nnn quit and change directory' function n --wraps nnn --description 'support nnn quit and change directory'

View File

@ -197,9 +197,13 @@ cmd Link %{{
fi fi
}} }}
# fzf + zlua # fzf + zlua/zoxide
cmd zlua ${{ cmd fzz ${{
sel=$(awk -F "|" '{print $1}' "$HOME/.local/share/zlua/zlua" | fzf | awk '{$1=$1};1') if command -v zoxide >/dev/null; then
sel=$(zoxide query --list | fzf --no-multi)
else
sel=$(awk -F "|" '{print $1}' "$HOME/.local/share/zlua/zlua" | fzf --no-multi | awk '{$1=$1};1')
fi
lf -remote "send $id cd \"$sel\"" lf -remote "send $id cd \"$sel\""
}} }}

50
home/.config/nnn/plugins/.cbcp Executable file
View File

@ -0,0 +1,50 @@
#!/usr/bin/env sh
# Description: Copy selection to system clipboard as newline-separated entries
# Dependencies:
# - tr
# - xclip/xsel (Linux)
# - pbcopy (macOS)
# - termux-clipboard-set (Termux)
# - clip.exe (WSL)
# - clip (Cygwin)
# - wl-copy (Wayland)
# - clipboard (Haiku)
#
# Limitation: breaks if a filename has newline in it
#
# Note: For a space-separated list:
# xargs -0 < "$SELECTION"
#
# Shell: POSIX compliant
# Author: Arun Prakash Jana
IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" # protect trailing \n
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
if which xsel >/dev/null 2>&1; then
# Linux
tr '\0' '\n' < "$selection" | xsel -bi
elif which xclip >/dev/null 2>&1; then
# Linux
tr '\0' '\n' < "$selection" | xclip -sel clip
elif which pbcopy >/dev/null 2>&1; then
# macOS
tr '\0' '\n' < "$selection" | pbcopy
elif which termux-clipboard-set >/dev/null 2>&1; then
# Termux
tr '\0' '\n' < "$selection" | termux-clipboard-set
elif which clip.exe >/dev/null 2>&1; then
# WSL
tr '\0' '\n' < "$selection" | clip.exe
elif which clip >/dev/null 2>&1; then
# Cygwin
tr '\0' '\n' < "$selection" | clip
elif which wl-copy >/dev/null 2>&1; then
# Wayland
tr '\0' '\n' < "$selection" | wl-copy
elif which clipboard >/dev/null 2>&1; then
# Haiku
tr '\0' '\n' < "$selection" | clipboard --stdin
fi

153
home/.config/nnn/plugins/.nmv Executable file
View File

@ -0,0 +1,153 @@
#!/usr/bin/env bash
# Description: An almost fully POSIX compliant batch file renamer
#
# Note: nnn auto-detects and invokes this plugin if available
# Whitespace is used as delimiter for read.
# The plugin doesn't support filenames with leading or trailing whitespace
#
# Capabilities:
# 1. Basic file rename
# 2. Detects order change
# 3. Can move files
# 4. Can remove files
# 5. Switch number pairs to swap filenames
#
# Shell: bash
# Author: KlzXS
EDITOR="${EDITOR:-vi}"
TMPDIR="${TMPDIR:-/tmp}"
INCLUDE_HIDDEN="${INCLUDE_HIDDEN:-0}"
VERBOSE="${VERBOSE:-0}"
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
exit_status=0
dst_file=$(mktemp "$TMPDIR/.nnnXXXXXX")
if [ -s "$selection" ]; then
printf "Rename 'c'urrent / 's'election? "
read -r resp
if ! [ "$resp" = "c" ] && ! [ "$resp" = "s" ]; then
exit 1
fi
fi
if [ "$resp" = "s" ]; then
arr=$(tr '\0' '\n' < "$selection")
else
if [ "$INCLUDE_HIDDEN" -eq 0 ]; then
arr=$(find . ! -name . -prune ! -name ".*" -print | sort)
else
arr=$(find . ! -name . -prune -print | sort)
fi
fi
lines=$(printf "%s\n" "$arr" | wc -l)
width=${#lines}
printf "%s" "$arr" | awk '{printf("%'"${width}"'d %s\n", NR, $0)}' > "$dst_file"
items=("~")
while IFS='' read -r line; do
items+=("$line");
done < <(printf "%s\n" "$arr")
$EDITOR "$dst_file"
while read -r num name; do
if [ -z "$name" ]; then
if [ -z "$num" ]; then
continue
fi
printf "%s: unable to parse line, aborting\n" "$0"
exit 1
fi
# check if $num is an integer
if [ ! "$num" -eq "$num" ] 2> /dev/null; then
printf "%s: unable to parse line, aborting\n" "$0"
exit 1
fi
src=${items[$num]}
if [ -z "$src" ]; then
printf "%s: unknown item number %s\n" "$0" "$num" > /dev/stderr
continue
elif [ "$name" != "$src" ]; then
if [ -z "$name" ]; then
continue
fi
if [ ! -e "$src" ] && [ ! -L "$src" ]; then
printf "%s: %s does not exit\n" "$0" "$src" > /dev/stderr
unset "items[$num]"
continue
fi
# handle swaps
if [ -e "$name" ] || [ -L "$name" ]; then
tmp="$name~"
c=0
while [ -e "$tmp" ] || [ -L "$tmp" ]; do
c=$((c+1))
tmp="$tmp~$c"
done
if mv "$name" "$tmp"; then
if [ "$VERBOSE" -ne 0 ]; then
printf "'%s' -> '%s'\n" "$name" "$tmp"
fi
else
printf "%s: failed to rename %s to %s: %s\n" "$0" "$name" "$tmp" "$!" > /dev/stderr
exit_status=1
fi
for key in "${!items[@]}"; do
if [ "${items[$key]}" = "$name" ]; then
items[$key]="$tmp"
fi
done
fi
dir=$(dirname "$name")
if [ ! -d "$dir" ] && ! mkdir -p "$dir"; then
printf "%s: failed to create directory tree %s\n" "$0" "$dir" > /dev/stderr
exit_status=1
elif ! mv "$src" "$name"; then
printf "%s: failed to rename %s to %s: %s\n" "$0" "$name" "$tmp" "$!" > /dev/stderr
exit_status=1
else
if [ -d "$name" ]; then
for key in "${!items[@]}"; do
items[$key]=$(printf "%s" "${items[$key]}" | sed "s|^$src\(\$\|\/\)|$name\1|")
done
if [ "$VERBOSE" -ne 0 ]; then
printf "'%s' => '%s'\n" "$src" "$name"
fi
else
true
if [ "$VERBOSE" -ne 0 ]; then
printf "'%s' -> '%s'\n" "$src" "$name"
fi
fi
fi
fi
unset "items[$num]"
done <"$dst_file"
unset "items[0]"
for item in "${items[@]}"; do
rm -ri "$item"
done
rm "$dst_file"
exit $exit_status

View File

@ -0,0 +1,38 @@
#!/usr/bin/env sh
# Description: Helper script for plugins
#
# Shell: POSIX compliant
# Author: Anna Arad
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
export selection
## Set CUR_CTX to 1 to open directory in current context
CUR_CTX=0
export CUR_CTX
## Ask nnn to switch to directory $1 in context $2.
## If $2 is not provided, the function asks explicitly.
nnn_cd () {
dir="$1"
if [ -z "$NNN_PIPE" ]; then
echo "No pipe file found" 1>&2
return
fi
if [ -n "$2" ]; then
context=$2
elif [ $CUR_CTX -ne 1 ]; then
printf "Choose context 1-4 (blank for current): "
read -r context
fi
printf "%s" "${context:-0}c$dir" > "$NNN_PIPE"
}
cmd_exists () {
which "$1" > /dev/null 2>&1
echo $?
}

22
home/.config/nnn/plugins/.ntfy Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env sh
# Description: Show a notification
#
# Details: nnn invokes this plugin to show notification when a cp/mv/rm operation is complete.
#
# Dependencies: notify-send (Ubuntu)/ntfy (https://github.com/dschep/ntfy)/osascript (macOS)/notify (Haiku)
#
# Shell: POSIX compliant
# Author: Anna Arad
OS="$(uname)"
if which notify-send >/dev/null 2>&1; then
notify-send nnn "Done!"
elif [ "$OS" = "Darwin" ]; then
osascript -e 'display notification "Done!" with title "nnn"'
elif which ntfy >/dev/null 2>&1; then
ntfy -t nnn send "Done!"
elif [ "$OS" = "Haiku" ]; then
notify --title "nnn" "Done!"
fi

View File

@ -8,19 +8,23 @@
. "$(dirname "$0")"/.nnn-plugin-helper . "$(dirname "$0")"/.nnn-plugin-helper
if which fzf >/dev/null 2>&1; then if which fzf >/dev/null 2>&1; then
fuzzy=fzf fuzzy="fzf --no-multi"
else else
exit 1 exit 1
fi fi
datafile="${_ZL_DATA:-$HOME/.local/share/zlua/zlua}" if command -v zoxide >/dev/null; then
if [ -f "$datafile" ]; then sel=$(zoxide query --list | $fuzzy)
# I read the data from z's file instead of calling the z command so that the data doesn't need to be processed twice
sel=$(awk -F "|" '{print $1}' "$datafile" | "$fuzzy" | awk '{$1=$1};1')
# NOTE: Uncomment this line and comment out the line above if you want to see the weightings of the dir's in the fzf pane
# sel=$(awk -F "|" '{printf "%s %s\n", $2, $1}' "$datafile" | "$fuzzy" | sed 's/^[0-9,.]* *//' | awk '{$1=$1};1')
else else
exit 1 datafile="${_ZL_DATA:-$HOME/.local/share/zlua/zlua}"
if [ -f "$datafile" ]; then
# I read the data from z's file instead of calling the z command so that the data doesn't need to be processed twice
sel=$(awk -F "|" '{print $1}' "$datafile" | $fuzzy | awk '{$1=$1};1')
# NOTE: Uncomment this line and comment out the line above if you want to see the weightings of the dir's in the fzf pane
# sel=$(awk -F "|" '{printf "%s %s\n", $2, $1}' "$datafile" | $fuzzy | sed 's/^[0-9,.]* *//' | awk '{$1=$1};1')
else
exit 1
fi
fi fi
printf "%s" "0c$sel" > "$NNN_PIPE" printf "%s" "0c$sel" > "$NNN_PIPE"

View File

@ -30,7 +30,7 @@ source $HOME/.config/nvim/plug-config/goyo.vim
source $HOME/.config/nvim/plug-config/illuminate.vim source $HOME/.config/nvim/plug-config/illuminate.vim
source $HOME/.config/nvim/plug-config/indentline.vim source $HOME/.config/nvim/plug-config/indentline.vim
" source $HOME/.config/nvim/plug-config/nerdtree.vim " source $HOME/.config/nvim/plug-config/nerdtree.vim
" source $HOME/.config/nvim/plug-config/nnn.vim source $HOME/.config/nvim/plug-config/nnn.vim
source $HOME/.config/nvim/plug-config/rainbow.vim source $HOME/.config/nvim/plug-config/rainbow.vim
source $HOME/.config/nvim/plug-config/rnvimr.vim source $HOME/.config/nvim/plug-config/rnvimr.vim
source $HOME/.config/nvim/plug-config/rooter.vim source $HOME/.config/nvim/plug-config/rooter.vim

View File

@ -113,7 +113,7 @@ Plug 'junegunn/fzf.vim'
" File managers " File managers
Plug 'kevinhwang91/rnvimr' Plug 'kevinhwang91/rnvimr'
Plug 'vifm/vifm.vim' Plug 'vifm/vifm.vim'
" Plug 'mcchrish/nnn.vim' Plug 'mcchrish/nnn.vim'
" Change windows " Change windows
Plug 't9md/vim-choosewin' Plug 't9md/vim-choosewin'
" Emacs like which key " Emacs like which key

7
home/.config/vifm/scripts/fzfz Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
if command -v zoxide >/dev/null; then
zoxide query --list | fzf --no-multi
else
awk -F "|" '{print $1}' "$HOME/.local/share/zlua/zlua" | fzf --no-multi | awk '{$1=$1};1'
fi

View File

@ -156,6 +156,12 @@ command! fzd : let $FZF_RES = term('fd --type d --follow --hidden --exclude .git
\| cd $FZF_RES \| cd $FZF_RES
\| endif \| endif
" fzf zoxide/zlua
command! z : let $FZF_RES = term('fzfz 2>&0')
\| if $FZF_RES != ''
\| cd $FZF_RES
\| endif
" ------------------------------------------------------------------------------ " ------------------------------------------------------------------------------
mark h ~/ mark h ~/

View File

@ -61,7 +61,7 @@ zman() {
# nnn with cd on quit # nnn with cd on quit
if command -v nnn >/dev/null; then if command -v nnn >/dev/null; then
alias nnn="nnn -Hc" alias nnn="nnn -Hdcx"
alias ncp="cat ${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} | tr '\0' '\n'" alias ncp="cat ${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} | tr '\0' '\n'"
n () { n () {

8
setup/xwinwrap.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
curl -fLo xwinwrap.c https://github.com/mmhobi7/xwinwrap/raw/master/xwinwrap.c
cc -g -O2 -Wall -Wextra -lX11 -lXext -lXrender -o xwinwrap xwinwrap.c
# Install
chmod 755 xwinwrap
mv -fv xwinwrap ~/.local/bin/xwinwrap