mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
69d63ff50e
* Fix conflict with #1006 * Queue/play in cmus player * Remove leftover comments * start_cmus function, optional xdotool dependency, better process waiting * start_cmus function, better process waiting, optional xdotool dep * Merge conflicts * Better reporting of past actions * Discriminate newly started queue and existing queue * Harmonize descriptions, rename cmusqueue to cmusq, clean cmusq code * Remove cmusqueue * Exit if cmus missing and style changes Co-authored-by: luukvbaal <31730729+luukvbaal@users.noreply.github.com>
54 lines
1.8 KiB
Bash
Executable file
54 lines
1.8 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 the subdir without navigating to the mountppoint
|
|
# or entering the remote name. Also works when hovering
|
|
# the mountpoint directly like vanilla `u`.
|
|
#
|
|
# Dependencies: fusermount
|
|
#
|
|
|
|
# Shell: POSIX compliant
|
|
# Authors: Kabouik & 0xACE
|
|
#
|
|
# TODO:
|
|
# - Avoid lazy unmount by forcing nnn context to leave the subfolder before fusermount.
|
|
# Tried `printf "%s" "0c$m" > "$NNN_PIPE"` but it breaks the nnn interface, see #854.
|
|
|
|
err=0
|
|
m=$HOME/.config/nnn/mounts
|
|
if [ "$PWD" = "$m" ]; then
|
|
# Allow running 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 within $m or a subdir, 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 it is
|
|
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 unmount fails, offer 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
|