prettier output for cclip
This commit is contained in:
68
files/cclip
68
files/cclip
@@ -5,7 +5,7 @@ _help() {
|
||||
SELF=$( basename "$0" )
|
||||
echo "Console Clipboard manager
|
||||
|
||||
Usage: $SELF [command] [name] [filename]
|
||||
Usage: $SELF [command] [clipboard name] [filename]
|
||||
|
||||
Short Command Description
|
||||
p paste Display on screen / copies to file
|
||||
@@ -18,8 +18,9 @@ _help() {
|
||||
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
|
||||
Clipboard Name: Any string for the clipboard name. default: 0
|
||||
Filename:
|
||||
If not given, defaults to clipboard name
|
||||
When reading from clipboard:
|
||||
File or folder to write the clipboard contents. If omitted: stdout
|
||||
When writing to clipboard:
|
||||
@@ -52,21 +53,33 @@ _list() {
|
||||
_msg "No clipboard entries"
|
||||
return
|
||||
}
|
||||
printf " %30s %8s %-19s %s\n" Type Size Date Name
|
||||
for n in *; do
|
||||
hl=$( _qCol W 2>/dev/null || true )
|
||||
he=$( _qCol y U 2>/dev/null || true )
|
||||
no=$( _qCol z 2>/dev/null || true )
|
||||
now=$( date -Idate )
|
||||
printf "%s%1s %5s %10s %s%s\n" "$he" T Size Added Name "$no"
|
||||
IFS=$'\n'
|
||||
while read n; do
|
||||
size=$( du -k -h -s --apparent-size "$n" | awk '{ print $1 }' )
|
||||
type=$( file -b "$n" )
|
||||
type=f
|
||||
if [[ -d "$n" ]]; then type=d; fi
|
||||
date=$( date -r "$n" -Iseconds )
|
||||
printf " %30s %8s %-19s %s\n" \
|
||||
"${type:0:30}" \
|
||||
date="${date::-6}"
|
||||
if [[ "$date" = "$now"* ]]; then
|
||||
date=${date#*T}
|
||||
else
|
||||
date=${date%T*}
|
||||
fi
|
||||
printf "%1s %5s %10s %s%s%s\n" \
|
||||
"${type}" \
|
||||
"$size" \
|
||||
"${date::-6}" \
|
||||
"$n"
|
||||
done
|
||||
"${date}" \
|
||||
"$hl" "$n" "$no"
|
||||
done < <( ls -t )
|
||||
}
|
||||
|
||||
_simple_list() {
|
||||
ls "$STORAGE"
|
||||
ls -1 "$STORAGE"
|
||||
}
|
||||
|
||||
|
||||
@@ -102,11 +115,16 @@ _write() {
|
||||
}
|
||||
|
||||
_write_files() { # name, file
|
||||
if [[ "$1" = "$2" ]]; then
|
||||
to=""
|
||||
else
|
||||
to=" to $1"
|
||||
fi
|
||||
if [[ $MOVE = true ]]; then
|
||||
echo Cutting "$2" to "$1"
|
||||
echo Cutting "${2}$to"
|
||||
mv "$2" "$STORAGE/$1"
|
||||
else
|
||||
echo Copying "$2" to "$1"
|
||||
echo Copying "${2}$to"
|
||||
cp -aT "$2" "$STORAGE/$1"
|
||||
fi
|
||||
touch "$STORAGE/$1"
|
||||
@@ -122,9 +140,15 @@ _read_menu() {
|
||||
ls
|
||||
read -e NAME
|
||||
popd &>/dev/null
|
||||
NAME=${NAME#\'}
|
||||
NAME=${NAME#\"}
|
||||
NAME=${NAME%\'}
|
||||
NAME=${NAME%\"}
|
||||
if [[ -e "$STORAGE/$NAME" ]]; then
|
||||
NAME=$( basename $NAME )
|
||||
NAME=$( basename "$NAME" )
|
||||
_read
|
||||
else
|
||||
echo "Could not find '$NAME'"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -155,7 +179,12 @@ _read() {
|
||||
|
||||
|
||||
_read_files() { # name, file
|
||||
echo Pasting "$1" to "$2"
|
||||
if [[ "$1" = "$2" ]]; then
|
||||
to=""
|
||||
else
|
||||
to=" to $2"
|
||||
fi
|
||||
echo Pasting "${1}$to"
|
||||
cp -aT "$STORAGE/$1" "$2"
|
||||
}
|
||||
|
||||
@@ -230,8 +259,9 @@ 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 ) );
|
||||
local IFS=$'"'"'\n'"'"'
|
||||
local remotelist=( $( eval CCLIP_EXEC simplelist ) )
|
||||
COMPREPLY=( $(compgen -W "${remotelist[*]}" -- $curr_arg ) );
|
||||
;;
|
||||
x|c*)
|
||||
COMPREPLY=( $(compgen -f -d -- $curr_arg ) );
|
||||
@@ -249,12 +279,12 @@ complete -F _CCLIP_EXEC_complete CCLIP_EXEC
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (( i=1; i<=$#; i++ )); do
|
||||
[[ "${!i}" = "-h" ]] && _help
|
||||
[[ "${!i}" = "--help" ]] && _help
|
||||
done
|
||||
_load_config
|
||||
source qolop &>/dev/null || true
|
||||
ARG1="$1"
|
||||
ARG2="$2"
|
||||
ARG3="$3"
|
||||
@@ -271,7 +301,7 @@ if [[ -z "$1" ]]; then CMD=list; fi
|
||||
[[ "$1" = "e" || "$1" = "edit" ]] && { CMD=edit; ARG1=$CMD; }
|
||||
[[ "$1" = "h" || "$1" = "help" ]] && _help
|
||||
[[ "$1" = "autocomplete" ]] && { _get_completer; exit; }
|
||||
[[ "$1" = "simplelist" ]] && { _simple_list; exit; }
|
||||
[[ "$1" = "simplelist" ]] && { _simple_list; exit; }
|
||||
|
||||
[[ -n "$1" ]] && [[ -e "$STORAGE"/"$1" ]] && CMD=read
|
||||
# if stdout redirected, default to read
|
||||
|
||||
Reference in New Issue
Block a user