From 43c072fd6af3be43428392bdaafe651d0d1dbf82 Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Tue, 14 Aug 2018 10:52:05 +0300 Subject: [PATCH] simple editor for cclip --- files/cclip | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/files/cclip b/files/cclip index 43bfbcb..ff32b40 100755 --- a/files/cclip +++ b/files/cclip @@ -8,10 +8,11 @@ _help() { Usage: $SELF [command] [name] [filename] Commands: - (r)ead - (w)rite - (d)elete - (l)ist [default] + (r)ead Display on screen / copies to file + (w)rite Save from stdin / from file + (d)elete Delete an entry + (e)dit Edit contents, with \$EDITOR + (l)ist [default] List names of clipboards Name: Any string for the clipboard name. default: 0 Filename: @@ -148,6 +149,14 @@ _get_file() { return 0 } +_edit() { + EDITOR=${EDITOR:-vi} + [[ -d "$STORAGE/$NAME" ]] && { + _msg "$NAME is a directory, can not edit" + exit 1 + } + $EDITOR "$STORAGE/$NAME" +} for (( i=1; i<=$#; i++ )); do [[ "${!i}" = "-h" ]] && _help [[ "${!i}" = "--help" ]] && _help @@ -161,6 +170,7 @@ CMD=list [[ "$1" = "w" || "$1" = "write" ]] && { CMD=write; ARG1=$CMD; } [[ "$1" = "d" || "$1" = "delete" || "$1" = "del" ]] && { CMD=delete; ARG1=$CMD; } [[ "$1" = "l" || "$1" = "list" ]] && { CMD=list; ARG1=$CMD; } +[[ "$1" = "e" || "$1" = "edit" ]] && { CMD=edit; ARG1=$CMD; } [[ "$1" = "h" || "$1" = "help" ]] && _help [[ -n "$1" ]] && [[ -e "$STORAGE"/"$1" ]] && CMD=read # if stdout redirected, default to read @@ -186,6 +196,10 @@ _get_file _write exit $? } +[[ "$CMD" = edit ]] && { + _edit + exit $? +} # TODO: