diff --git a/.bash_completion.d/nc-mount b/.bash_completion.d/nc-mount new file mode 100644 index 0000000000000000000000000000000000000000..3595544a7ef0bc9d473f46aad5d7e806aaf728ff --- /dev/null +++ b/.bash_completion.d/nc-mount @@ -0,0 +1,24 @@ +# vim: ft=bash + +_nc_mount () { + local cur prev words cword opts + _init_completion || return + opts='-a --all -h --help -l --list' + + if [[ $cur == -* ]] + then + COMPREPLY=($(compgen -W "$opts" -- "$cur")) + else + local IFS=$'\n' + declare -a candidates + candidates=($(compgen -W "$(nc-mount -l)" -- "$cur")) + if [ ${#candidates[*]} -eq 0 ] + then + COMPREPLY=() + else + COMPREPLY=($(printf '%q\n' "${candidates[@]}")) + fi + fi +} + +complete -F _nc_mount nc-mount diff --git a/Documents/bin/nc-mount b/Documents/bin/nc-mount new file mode 100755 index 0000000000000000000000000000000000000000..8a71fcff8677b21c7a28a9b208b5e14b62375330 --- /dev/null +++ b/Documents/bin/nc-mount @@ -0,0 +1,39 @@ +#!/bin/sh +set -eu + +command -v rclone >/dev/null || { echo 'rclone not found.' >&2; exit 1; } + +usage () { + echo "$0: [-a|--all] [-l|--list] [FOLDER]" >&2 + exit 1 +} + +_mount () { + folder="$1" + mkfolder -p "$HOME/$folder" + rclone mount \ + --allow-non-empty \ + --daemon \ + --gid "$(id -g)" \ + --vfs-cache-mode full \ + --uid "$(id -u)" \ + "nextcloud:$folder" \ + "$HOME/$folder" +} + +[ "$#" -eq 1 ] || usage + +folders="$(rclone lsd nextcloud: | cut -c 44- | grep -vx 'System information')" + +case "$1" in + -h|--help) usage;; + -l|--list) echo "$folders";; + -a|--all) echo "$folders" | xargs -I % "$0" "%";; + *) if echo "$folders" | grep -qx "$1" + then + _mount "$1" + else + echo "Folder $1 not found in Nextcloud." >&2 + exit 1 + fi;; +esac