From 2ae911f547bb1112a097b231776c92a966ce0e2b Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Tue, 28 Jan 2020 13:47:55 +0200 Subject: [PATCH] paste with move --- files/cclip | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/files/cclip b/files/cclip index cd73923..ebe4941 100755 --- a/files/cclip +++ b/files/cclip @@ -8,9 +8,10 @@ _help() { Usage: $SELF [command] [clipboard name] [filename] Short Command Description - p paste Display on screen / copies to file - c copy Save from stdin / from file + c copy Copy from file / stdin x cut Move file to clipboard + p paste Paste to file / stdout + o move Paste to file, by moving (clipboard deleted) d delete Delete an entry D Delete Clear the whole clibboard e edit Edit contents, with \$EDITOR @@ -21,6 +22,7 @@ _help() { Clipboard Name: Any string for the clipboard name. default: 0 Filename: If not given, defaults to clipboard name + - uses stdout/stdin When reading from clipboard: File or folder to write the clipboard contents. If omitted: stdout When writing to clipboard: @@ -184,8 +186,13 @@ _read_files() { # name, file else to=" to $2" fi - echo Pasting "${1}$to" - cp -aT "$STORAGE/$1" "$2" + if [[ $MOVE = true ]]; then + echo Moving "${1}$to" + mv "$STORAGE/$1" "$2" + else + echo Pasting "${1}$to" + cp -aT + fi } _read_stdout() { # name @@ -254,11 +261,11 @@ _get_completer() { 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 ) ); + COMPREPLY=( $(compgen -W "help autocomplete l list c copy x cut p paste o move delete Delete pmenu" -- $curr_arg ) ); fi if [[ $COMP_CWORD -eq 2 ]]; then case ${COMP_WORDS[$(( $COMP_CWORD - 1 ))]} in - p|paste|d*) + o|move|p|paste|d*) local IFS=$'"'"'\n'"'"' local remotelist=( $( eval CCLIP_EXEC simplelist ) ) COMPREPLY=( $(compgen -W "${remotelist[*]}" -- $curr_arg ) ); @@ -292,6 +299,7 @@ MOVE=false CMD=help if [[ -z "$1" ]]; then CMD=list; fi [[ "$1" = "p" || "$1" = "paste" ]] && { CMD=read; ARG1=$CMD; } +[[ "$1" = "o" || "$1" = "move" ]] && { CMD=read; ARG1=$CMD; MOVE=true; } [[ "$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; }