fixed autocompletion as it was somehow dropped from the project, added screenshots to readme

master
Anton Lydike 2 years ago
parent 9379c6c471
commit 5781430811

@ -46,8 +46,12 @@ It also prints the device, the devices label, if available (otherwise `???`) and
You can mount a volume by simply specifying `mnt IDENTIFIER`, it will autocomplete available block devices for you, but you can also specify (parts of) labels or size, basically anything that identifies the volume uniquely. (The volume is selected by grepping for `IDENTIFIER` in the output of `mnt_core_list_mounts`)
![Mount autocompletion in action](img/mount-completions.png)
Unmounting is just as easy, you can run `mnt -u IDENTIFIER`, with the same rules for the identifier. The autocompletion will only offer you already mounted devices.
![Unmounting volumes](img/mount-unmount-cycle.png)
### Configuration
The script mounts block devices using `udisksctl` by default. If you have a more involved setup, you can edit the `.mounts` file in your home directory. The format is roughly documented in the file, but I'll go into more detail here:

@ -0,0 +1,43 @@
complete -c mnt -f
# add flags
complete -c mnt -s h -l help -d 'Print a short help text and exit'
complete -c mnt -s l -l list -d 'List information on all available mounts'
complete -c mnt -s f -l full-paths -d 'Print full paths instead of the shorter versions'
complete -c mnt -s u -l unmount -d 'Unmount a volume' -a "(_mnt_complete_volumes unmount)"
complete -c mnt -n 'not _mnt_seen_flag u unmount; and _mnt_not_seen_any_arg' -a '(_mnt_complete_volumes mount)'
complete -c mnt -n '_mnt_seen_flag u unmount; and _mnt_not_seen_any_arg' -a '(_mnt_complete_volumes unmount)'
function _mnt_complete_volumes
for line in (mnt_core_list_mounts | mnt_core_filter $argv[1])
mnt_core_pretty_print_line $argv[1] $line
end
end
function _mnt_seen_flag
# usage: _mnt_seen_flag <shorthand> <longhand>
# short/longhand without leading dashes
set -l cmd (commandline -po)
set -e cmd[1]
if string match -r -- '^(-[^-]*'"$argv[1]"'[^-]*|--'"$argv[2]"')$' $cmd
return 0
end
return 1
end
function _mnt_not_seen_any_arg
set -l cmd (commandline -po)
set -e cmd[1]
if not string match -v -- '-*' $cmd
return 0
else
return 1
end
end

@ -2,7 +2,7 @@ set _MNT_SEEN_DEVICES /dev/sda /dev/nvme0n1
function mnt
argparse --name=mnt 'h/help' 'l/list' 'f/full-paths' 'u/unmount' -- $argv
argparse --name=mnt 'h/help' 'l/list' 'f/full-paths' 'u/unmount=' -- $argv
if set -q _flag_help
echo "mnt - A mounting utility"
@ -25,12 +25,14 @@ function mnt
return 0
end
if set -q _flag_list; or ! count $argv > /dev/null
set -l unmount_target (coalesce $_flag_unmount $argv[1])
if set -q _flag_list; or test -z $unmount_target
mnt_core_pretty_list_mounts $_flag_full_paths | sort
return 0
end
set -l selected_mount (mnt_core_list_mounts | rg -- (string trim -rc '/' -- $argv[1]))
set -l selected_mount (mnt_core_list_mounts | rg -- $unmount_target)
if test (count $selected_mount) -gt 1
echo '"'"$argv[1]"'" is ambigous, it matched:'
@ -202,11 +204,11 @@ function mnt_core_filter
if test -b $info[1]
echo $line
end
case mounted
case mounted unmount
if mnt_core_mount_point $info[1] > /dev/null
echo $line
end
case unmounted
case unmounted mount
if test -b $info[1]; and ! mnt_core_mount_point $info[1] > /dev/null
echo $line
end

@ -29,7 +29,7 @@ function mount-luks
set -l pass_name $argv[2]
set -l mapper $argv[3]
pass $PASS_NAME | head -n 1 | sudo cryptsetup luksOpen $device $mapper -
pass $pass_name | head -n 1 | sudo cryptsetup luksOpen $device $mapper -
udisksctl mount -b /dev/mapper/$mapper
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

@ -54,6 +54,30 @@ function install_copy
cp $argv[1] $argv[2]
end
function uninstall_mnt
# uninstall mode!
echo "Uninstalling mnt..."
for file in $core_files $dependencies
if test -f $fish_config_path/$file
rm $fish_config_path/$file
echo " Removed $fish_config_path/$file"
else
echo " $file was not installed."
end
end
if set -q _flag_extras
echo "Uninstalling extras..."
for file in $extras
if test -f $fish_config_path/$file
rm $fish_config_path/$file
echo " Removed $fish_config_path/$file"
else
echo " $file was not installed."
end
end
end
end
function install
argparse 'h/help' 'c/copy' 'f/force' 'e/extras' 'C/clean' -- $argv
@ -104,27 +128,7 @@ function install
# check for uninstall flag
if set -q _flag_clean
# uninstall mode!
echo "Uninstalling mnt..."
for file in $core_files $dependencies
if test -f $fish_config_path/$file
rm $fish_config_path/$file
echo " Removed $fish_config_path/$file"
else
echo " $file was not installed."
end
end
if set -q _flag_extras
echo "Uninstalling extras..."
for file in $extras
if test -f $fish_config_path/$file
rm $fish_config_path/$file
echo " Removed $fish_config_path/$file"
else
echo " $file was not installed."
end
end
end
uninstall_mnt
return 0
end

Loading…
Cancel
Save