simple editor for cclip
This commit is contained in:
22
files/cclip
22
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:
|
||||
|
||||
Reference in New Issue
Block a user