rename commands to more generally accepted

This commit is contained in:
2020-01-28 10:37:03 +02:00
parent 5d805a77fe
commit adba4c439c

View File

@@ -7,14 +7,16 @@ _help() {
Usage: $SELF [command] [name] [filename] Usage: $SELF [command] [name] [filename]
Commands: Short Command Description
(r)ead Display on screen / copies to file p paste Display on screen / copies to file
(w)rite Save from stdin / from file c copy Save from stdin / from file
(d)elete Delete an entry x cut Move file to clipboard
(D)elete Clear the whole clibboard d delete Delete an entry
(e)dit Edit contents, with \$EDITOR D Delete Clear the whole clibboard
(l)ist [default] List names of clipboards e edit Edit contents, with \$EDITOR
rmenu/readmenu Read a file/folder using a simple menu (for MC ex.) l list [default] List names of clipboards
pmenu pastemenu Paste a file/folder using a simple menu (ex. for MC)
autocomplete Get Bash autocompletion script
Name: Any string for the clipboard name. default: 0 Name: Any string for the clipboard name. default: 0
Filename: Filename:
@@ -63,6 +65,11 @@ _list() {
done done
} }
_simple_list() {
ls "$STORAGE"
}
_write() { _write() {
# no file mentioned, use stdin # no file mentioned, use stdin
[[ -z "$FILE" ]] && stream_in=1 [[ -z "$FILE" ]] && stream_in=1
@@ -95,10 +102,16 @@ _write() {
} }
_write_files() { # name, file _write_files() { # name, file
echo Storing "$2" to "$1" if [[ $MOVE = true ]]; then
cp -aT "$2" "$STORAGE/$1" echo Cutting "$2" to "$1"
mv "$2" "$STORAGE/$1"
else
echo Copying "$2" to "$1"
cp -aT "$2" "$STORAGE/$1"
fi
touch "$STORAGE/$1" touch "$STORAGE/$1"
} }
_write_stdin() { # name _write_stdin() { # name
cat - > "$STORAGE/$1" cat - > "$STORAGE/$1"
} }
@@ -118,7 +131,7 @@ _read_menu() {
_read() { _read() {
[[ -e "$STORAGE/$NAME" ]] || { [[ -e "$STORAGE/$NAME" ]] || {
_msg "No such clipboard" _msg "No such clipboard: '$NAME'"
return return
} }
[[ "$FILE" = "-" ]] && stream_out=1 [[ "$FILE" = "-" ]] && stream_out=1
@@ -142,7 +155,7 @@ _read() {
_read_files() { # name, file _read_files() { # name, file
echo Reading "$1" to "$2" echo Pasting "$1" to "$2"
cp -aT "$STORAGE/$1" "$2" cp -aT "$STORAGE/$1" "$2"
} }
@@ -205,6 +218,38 @@ _edit() {
} }
$EDITOR "$STORAGE/$NAME" $EDITOR "$STORAGE/$NAME"
} }
_get_completer() {
self=$( basename $( readlink -f "$0" ) )
echo '_CCLIP_EXEC_complete() {
local curr_arg
curr_arg=${COMP_WORDS[COMP_CWORD]}
if [[ $COMP_CWORD -eq 1 ]]; then
COMPREPLY=( $(compgen -W "help autocomplete l list c copy x cut p paste delete Delete pmenu" -- $curr_arg ) );
fi
if [[ $COMP_CWORD -eq 2 ]]; then
case ${COMP_WORDS[$(( $COMP_CWORD - 1 ))]} in
p|paste|d*)
local remotelist=$( eval CCLIP_EXEC simplelist )
COMPREPLY=( $(compgen -W "$remotelist" -- $curr_arg ) );
;;
x|c*)
COMPREPLY=( $(compgen -f -d -- $curr_arg ) );
;;
esac
fi
if [[ $COMP_CWORD -eq 3 ]]; then
COMPREPLY=( $(compgen -f -d -- $curr_arg ) );
fi
}
complete -F _CCLIP_EXEC_complete CCLIP_EXEC
# Run me as: source <( CCLIP_EXEC autocomplete )
' | sed "s,CCLIP_EXEC,$self,g"
exit 0
}
for (( i=1; i<=$#; i++ )); do for (( i=1; i<=$#; i++ )); do
[[ "${!i}" = "-h" ]] && _help [[ "${!i}" = "-h" ]] && _help
[[ "${!i}" = "--help" ]] && _help [[ "${!i}" = "--help" ]] && _help
@@ -213,21 +258,31 @@ _load_config
ARG1="$1" ARG1="$1"
ARG2="$2" ARG2="$2"
ARG3="$3" ARG3="$3"
CMD=list MOVE=false
[[ "$1" = "r" || "$1" = "read" ]] && { CMD=read; ARG1=$CMD; } CMD=help
[[ "$1" = "rmenu" || "$1" = "readmenu" ]] && { CMD=read_menu; ARG1=$CMD; } if [[ -z "$1" ]]; then CMD=list; fi
[[ "$1" = "w" || "$1" = "write" ]] && { CMD=write; ARG1=$CMD; } [[ "$1" = "p" || "$1" = "paste" ]] && { CMD=read; ARG1=$CMD; }
[[ "$1" = "pmenu" || "$1" = "pastemenu" ]] && { CMD=read_menu; ARG1=$CMD; }
[[ "$1" = "c" || "$1" = "copy" ]] && { CMD=write; ARG1=$CMD; }
[[ "$1" = "x" || "$1" = "cut" ]] && { CMD=write; ARG1=$CMD; MOVE=true; }
[[ "$1" = "d" || "$1" = "delete" || "$1" = "del" ]] && { CMD=delete; ARG1=$CMD; } [[ "$1" = "d" || "$1" = "delete" || "$1" = "del" ]] && { CMD=delete; ARG1=$CMD; }
[[ "$1" = "D" || "$1" = "Delete" || "$1" = "Del" ]] && { CMD=delete_all; ARG1=$CMD; } [[ "$1" = "D" || "$1" = "Delete" || "$1" = "Del" ]] && { CMD=delete_all; ARG1=$CMD; }
[[ "$1" = "l" || "$1" = "list" ]] && { CMD=list; ARG1=$CMD; } [[ "$1" = "l" || "$1" = "list" ]] && { CMD=list; ARG1=$CMD; }
[[ "$1" = "e" || "$1" = "edit" ]] && { CMD=edit; ARG1=$CMD; } [[ "$1" = "e" || "$1" = "edit" ]] && { CMD=edit; ARG1=$CMD; }
[[ "$1" = "h" || "$1" = "help" ]] && _help [[ "$1" = "h" || "$1" = "help" ]] && _help
[[ "$1" = "autocomplete" ]] && { _get_completer; exit; }
[[ "$1" = "simplelist" ]] && { _simple_list; exit; }
[[ -n "$1" ]] && [[ -e "$STORAGE"/"$1" ]] && CMD=read [[ -n "$1" ]] && [[ -e "$STORAGE"/"$1" ]] && CMD=read
# if stdout redirected, default to read # if stdout redirected, default to read
[ -t 1 ] || CMD=read [ -t 1 ] || CMD=read
# if stdin comes from stream, default to write # if stdin comes from stream, default to write
[ -t 0 ] || CMD=write [ -t 0 ] || CMD=write
[[ "$CMD" = help ]] && {
_help
exit $?
}
[[ "$CMD" = list ]] && { [[ "$CMD" = list ]] && {
_list _list
exit $? exit $?