diff --git a/README.md b/README.md index b18a969..3951b31 100644 --- a/README.md +++ b/README.md @@ -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) - **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) - - **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) - **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) diff --git a/home/.bashrc-bloated b/home/.bashrc-bloated index 0d0090c..3b6c0c6 100644 --- a/home/.bashrc-bloated +++ b/home/.bashrc-bloated @@ -522,7 +522,7 @@ basherpacks_update() { # nnn with cd on quit 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'" n () { diff --git a/home/.config/fish/conf.d/aliases.fish b/home/.config/fish/conf.d/aliases.fish index 20c94eb..60b7644 100644 --- a/home/.config/fish/conf.d/aliases.fish +++ b/home/.config/fish/conf.d/aliases.fish @@ -44,7 +44,7 @@ abbr youbest 'youtube-dl -f bestvideo+bestaudio' abbr youlist 'youtube-dl -f bestvideo+bestaudio --yes-playlist' # nnn 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'" function n --wraps nnn --description 'support nnn quit and change directory' diff --git a/home/.config/lf/lfrc b/home/.config/lf/lfrc index a5238a7..2084266 100644 --- a/home/.config/lf/lfrc +++ b/home/.config/lf/lfrc @@ -197,9 +197,13 @@ cmd Link %{{ fi }} -# fzf + zlua -cmd zlua ${{ - sel=$(awk -F "|" '{print $1}' "$HOME/.local/share/zlua/zlua" | fzf | awk '{$1=$1};1') +# fzf + zlua/zoxide +cmd fzz ${{ + 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\"" }} diff --git a/home/.config/nnn/plugins/.cbcp b/home/.config/nnn/plugins/.cbcp new file mode 100755 index 0000000..04a09dc --- /dev/null +++ b/home/.config/nnn/plugins/.cbcp @@ -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 diff --git a/home/.config/nnn/plugins/.nmv b/home/.config/nnn/plugins/.nmv new file mode 100755 index 0000000..7762546 --- /dev/null +++ b/home/.config/nnn/plugins/.nmv @@ -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 diff --git a/home/.config/nnn/plugins/.nnn-plugin-helper b/home/.config/nnn/plugins/.nnn-plugin-helper new file mode 100755 index 0000000..bcb9649 --- /dev/null +++ b/home/.config/nnn/plugins/.nnn-plugin-helper @@ -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 $? +} diff --git a/home/.config/nnn/plugins/.ntfy b/home/.config/nnn/plugins/.ntfy new file mode 100755 index 0000000..3a7f27f --- /dev/null +++ b/home/.config/nnn/plugins/.ntfy @@ -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 diff --git a/home/.config/nnn/plugins/fzz b/home/.config/nnn/plugins/fzz index c715d00..ee230b1 100755 --- a/home/.config/nnn/plugins/fzz +++ b/home/.config/nnn/plugins/fzz @@ -8,19 +8,23 @@ . "$(dirname "$0")"/.nnn-plugin-helper if which fzf >/dev/null 2>&1; then - fuzzy=fzf + fuzzy="fzf --no-multi" else exit 1 fi -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') +if command -v zoxide >/dev/null; then + sel=$(zoxide query --list | $fuzzy) 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 printf "%s" "0c$sel" > "$NNN_PIPE" diff --git a/home/.config/nvim/init.vim b/home/.config/nvim/init.vim index cb66f02..978e805 100644 --- a/home/.config/nvim/init.vim +++ b/home/.config/nvim/init.vim @@ -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/indentline.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/rnvimr.vim source $HOME/.config/nvim/plug-config/rooter.vim diff --git a/home/.config/nvim/vim-plug/vim-plug.vim b/home/.config/nvim/vim-plug/vim-plug.vim index 15d52c7..2400551 100644 --- a/home/.config/nvim/vim-plug/vim-plug.vim +++ b/home/.config/nvim/vim-plug/vim-plug.vim @@ -113,7 +113,7 @@ Plug 'junegunn/fzf.vim' " File managers Plug 'kevinhwang91/rnvimr' Plug 'vifm/vifm.vim' -" Plug 'mcchrish/nnn.vim' +Plug 'mcchrish/nnn.vim' " Change windows Plug 't9md/vim-choosewin' " Emacs like which key diff --git a/home/.config/vifm/scripts/fzfz b/home/.config/vifm/scripts/fzfz new file mode 100755 index 0000000..aff0662 --- /dev/null +++ b/home/.config/vifm/scripts/fzfz @@ -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 diff --git a/home/.config/vifm/vifmrc b/home/.config/vifm/vifmrc index a9496e1..0c84b13 100644 --- a/home/.config/vifm/vifmrc +++ b/home/.config/vifm/vifmrc @@ -156,6 +156,12 @@ command! fzd : let $FZF_RES = term('fd --type d --follow --hidden --exclude .git \| cd $FZF_RES \| endif +" fzf zoxide/zlua +command! z : let $FZF_RES = term('fzfz 2>&0') + \| if $FZF_RES != '' + \| cd $FZF_RES + \| endif + " ------------------------------------------------------------------------------ mark h ~/ diff --git a/home/.config/zsh/aliases.zsh b/home/.config/zsh/aliases.zsh index 33f23a4..8ff95ca 100644 --- a/home/.config/zsh/aliases.zsh +++ b/home/.config/zsh/aliases.zsh @@ -61,7 +61,7 @@ zman() { # nnn with cd on quit 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'" n () { diff --git a/setup/xwinwrap.sh b/setup/xwinwrap.sh new file mode 100755 index 0000000..ff625ef --- /dev/null +++ b/setup/xwinwrap.sh @@ -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