mirror of
https://github.com/jarun/nnn.git
synced 2024-11-17 08:32:36 +00:00
c2aeb51bcc
* Fuzzy find plugins and run them * Hide find warning when $otherplugins is not set * Fix prompt on error 2 * Use /home/mathieu * unmount-parent plugin * Add dependencies and shell description * Add dependencies and fix CI issue? * Improve fzfplug prompt, fix shellcheck warnings, restore mistakenly deleted line in README * Typo * Make both scripts POSIX-compliant and small improvements * Final cosmetic changes * bis * Clarify description * Typo * Typo * Better support for custom dirs and use bat if available Co-authored-by: M <>
49 lines
1.9 KiB
Bash
Executable file
49 lines
1.9 KiB
Bash
Executable file
#!/usr/bin/env sh
|
|
|
|
# Description: Autodetects a nnn remote mountpoint (mounted with `c`) from any of its subfolders and allows unmounting it
|
|
# from there without first going back to the top or entering the remote name. Also works when hovering the mountpoint
|
|
# directly like vanilla `u`.
|
|
#
|
|
# Dependencies: fusermount
|
|
# Shell: POSIX compliant
|
|
# Authors: Kabouik & 0xACE
|
|
#
|
|
# TODO: Try better avoiding lazy unmount by forcing nnn context to leave the subfolder before fusermount.
|
|
# I tried `printf "%s" "0c$m" > "$NNN_PIPE"` but this would break nnn UI all the time, see #854.
|
|
|
|
# ENVIRONMENT
|
|
err=0
|
|
m=$HOME/.config/nnn/mounts
|
|
if [ "$PWD" = "$m" ]; then # ALLOW USING THE SCRIPT ON HOVERED DIRECTORY IF USER IS IN ~/.config/nnn/mounts
|
|
d="$1"
|
|
else
|
|
d=$(dirname "$(readlink -f "$1")" | grep -oP "^$m\K.*" | cut -d"/" -f2)
|
|
fi
|
|
|
|
# TEST IF USER IS CURRENTLY WITHIN $m OR A SUBFOLDER, ABORT IF NOT
|
|
if [ "$d" = "" ]; then
|
|
clear && printf "You are not in a remote folder mounted with nnn. Press return to continue. " && read -r _
|
|
else
|
|
# TEST IF $m/$d IS A MOUNTPOINT AND TRY UNMOUNTING IF YES
|
|
mountpoint -q -- "$m/$d"
|
|
if [ "$?" -eq "1" ]; then
|
|
clear && printf "Parent '%s' is not a mountpoint. Press return to continue. " "$d" && read -r _
|
|
else
|
|
cd "$m" && fusermount -uq "$m/$d" || err=1
|
|
if [ "$err" -eq "0" ]; then
|
|
rmdir "$m/$d" && clear && printf "Parent '%s' unmounted." "$d"
|
|
else
|
|
clear && printf "Failed to unmount. Try lazy unmount? [Yy/Nn] " && read -r
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
# IF FAILURE TO UNMOUNT, OFFER TO TRY LAZY UNMOUNT
|
|
if [ "$REPLY" = "y" ] || [ "$REPLY" = "Y" ]; then
|
|
err=0
|
|
cd "$m" && fusermount -uqz "$m/$d" || err=1
|
|
if [ "$err" -eq "0" ]; then
|
|
rmdir "$m/$d" && clear && printf "Parent '%s' unmounted with lazy unmount. " "$d"
|
|
fi
|
|
fi
|