trying to autocomp with spaces...

This commit is contained in:
Q
2022-10-17 22:18:15 +03:00
parent 0aa277a921
commit 40fed6563f

View File

@@ -39,7 +39,7 @@ Get autocomplete:
Config: Config:
CCLIP_HOME environment variable sets clipboard storage folder, CCLIP_HOME environment variable sets clipboard storage folder,
defauls to ~/.cache/cclip defauls to ~/.cache/cclip
" "
exit exit
} }
@@ -93,20 +93,20 @@ _list() {
date="${date:2:8}" date="${date:2:8}"
fi fi
printf "%-${longest}s %-10s\n" \ printf "%-${longest}s %-10s\n" \
"$name" \ "$name" \
"${date}" "${date}"
while read f; do while read f; do
if [[ ! -e "$f" ]]; then if [[ ! -e "$f" ]]; then
size=MISS"!" size=MISS"!"
else else
size=$( du -k -h -s --apparent-size "$f" | awk '{ print $1 }' ) size=$( du -k -h -s --apparent-size "$f" | awk '{ print $1 }' )
fi fi
printf "%-${longest}s %5s %s%s%s\n" \ printf "%-${longest}s %5s %s%s%s\n" \
" " \ " " \
"$size" \ "$size" \
"$HL" "${f}" \ "$HL" "${f}" \
"$NO" "$NO"
done < "${STORAGE}/$name" done < "${STORAGE}/$name"
done < <( ls "${STORAGE}" -t ) done < <( ls "${STORAGE}" -t )
} }
@@ -136,7 +136,7 @@ _copy() {
origname="$name" origname="$name"
path=$( readlink -f "${!i}" ) path=$( readlink -f "${!i}" )
if [[ -d "$path" ]]; then if [[ -d "$path" ]]; then
path="$path/" path="$path/"
fi fi
printf "%s\n" "$path" >> "$STORAGE/${CLIPBOARD}" printf "%s\n" "$path" >> "$STORAGE/${CLIPBOARD}"
done done
@@ -157,7 +157,7 @@ _edit() {
continue continue
fi fi
${VISUAL:-vim} "$STORAGE/${CLIPBOARD}" ${VISUAL:-vim} "$STORAGE/${CLIPBOARD}"
_list l "$CLIPBOARD" _list l "$CLIPBOARD"
done done
} }
@@ -176,12 +176,12 @@ _paste() {
if [[ ! -f "$STORAGE/${!i}" ]]; then if [[ ! -f "$STORAGE/${!i}" ]]; then
# no such clipboard # no such clipboard
if [[ $i -gt 2 ]]; then if [[ $i -gt 2 ]]; then
if [[ $i -eq $numargs ]]; then if [[ $i -eq $numargs ]]; then
# but argument is last (but not only) # but argument is last (but not only)
OUTPUT=${!i} OUTPUT=${!i}
numargs=$(( numargs - 1 )) numargs=$(( numargs - 1 ))
continue continue
fi fi
fi fi
_err "No such clipboard: ${!i}" _err "No such clipboard: ${!i}"
return return
@@ -201,7 +201,7 @@ _paste() {
done done
if [[ ! "$single_copied" = 1 ]]; then if [[ ! "$single_copied" = 1 ]]; then
_paste_clipboard "$CLIPBOARD" _paste_clipboard "$CLIPBOARD"
fi fi
} }
@@ -252,8 +252,8 @@ _paste_single() {
post=0 post=0
while [[ -e "${OUTPUT}/${basetarget}${extension}" ]]; do while [[ -e "${OUTPUT}/${basetarget}${extension}" ]]; do
post=$(( post + 1 )) post=$(( post + 1 ))
basetarget="${origbase}-${post}" basetarget="${origbase}-${post}"
done done
target="${basetarget}${extension}" target="${basetarget}${extension}"
@@ -286,14 +286,14 @@ _paste_single() {
if [[ -f "${1}" ]]; then if [[ -f "${1}" ]]; then
if [[ $( stat -c "%s" "$1" ) -gt 100000000 ]]; then if [[ $( stat -c "%s" "$1" ) -gt 100000000 ]]; then
if which pv &>/dev/null; then if which pv &>/dev/null; then
# source is file, and over 100Mb # source is file, and over 100Mb
pv "${1}" > "${OUTPUT}/$target" || { pv "${1}" > "${OUTPUT}/$target" || {
keeplink=1 keeplink=1
return 1 return 1
} }
chmod --reference="${1}" "${OUTPUT}/$target" chmod --reference="${1}" "${OUTPUT}/$target"
chown --reference="${1}" "${OUTPUT}/$target" chown --reference="${1}" "${OUTPUT}/$target"
return return
fi fi
fi fi
fi fi
@@ -360,55 +360,55 @@ _delete_all() {
} }
_err() { _err() {
echo "${HERR}$@${NO}" echo "${HERR}$@${NO}"
} }
_gui() { _gui() {
# GUI is intended for mc (midnight commander) # GUI is intended for mc (midnight commander)
# Example menu config # Example menu config
# 5 cclip # 5 cclip
# cclip mc %s # cclip mc %s
CLIPBOARD=mc CLIPBOARD=mc
fileargs=$(( $# - 1 )) fileargs=$(( $# - 1 ))
softlink=0 softlink=0
hardlink=0 hardlink=0
keeplink=1 keeplink=1
movelink=0 movelink=0
while :; do while :; do
_list l $CLIPBOARD _list l $CLIPBOARD
echo "$fileargs files selected" echo "$fileargs files selected"
read -s -p "(q)uit/(c)opy/(p)aste/(d)elete/(e)dit/(b)oard/(o)pts" -n 1 key read -s -p "(q)uit/(c)opy/(p)aste/(d)elete/(e)dit/(b)oard/(o)pts" -n 1 key
echo $'\n' echo $'\n'
if [[ "$key" = "q" ]]; then if [[ "$key" = "q" ]]; then
break break
fi fi
if [[ "$key" = "c" ]]; then if [[ "$key" = "c" ]]; then
_copy c "${@:2}" _copy c "${@:2}"
break break
fi fi
if [[ "$key" = "p" ]]; then if [[ "$key" = "p" ]]; then
_paste_clipboard "$CLIPBOARD" _paste_clipboard "$CLIPBOARD"
break break
fi fi
if [[ "$key" = "d" ]]; then if [[ "$key" = "d" ]]; then
_delete d mc _delete d mc
fi fi
if [[ "$key" = "e" ]]; then if [[ "$key" = "e" ]]; then
_edit e mc _edit e mc
fi fi
if [[ "$key" = "b" ]]; then if [[ "$key" = "b" ]]; then
echo -n "Populated clipboards: " echo -n "Populated clipboards: "
_simple_list | xargs echo _simple_list | xargs echo
echo Change board: echo Change board:
read -e -i "$CLIPBOARD" CLIPBOARD read -e -i "$CLIPBOARD" CLIPBOARD
fi fi
if [[ "$key" = "o" ]]; then if [[ "$key" = "o" ]]; then
_gui_opts _gui_opts
fi fi
done done
} }
_gui_opts() { _gui_opts() {
@@ -422,7 +422,7 @@ Options:
d keep clipboard: %s d keep clipboard: %s
e exit e exit
Toggle option:\n" "$movelink" "$softlink" "$hardlink" "$keeplink" Toggle option:\n" "$movelink" "$softlink" "$hardlink" "$keeplink"
read -s -n 1 optkey read -s -n 1 optkey
case "$optkey" in case "$optkey" in
@@ -430,7 +430,7 @@ Toggle option:\n" "$movelink" "$softlink" "$hardlink" "$keeplink"
s) softlink=$(( 1 - softlink )) ;; s) softlink=$(( 1 - softlink )) ;;
l) hardlink=$(( 1 - hardlink )) ;; l) hardlink=$(( 1 - hardlink )) ;;
d) keeplink=$(( 1 - keeplink )) ;; d) keeplink=$(( 1 - keeplink )) ;;
e) break;; e) break ;;
esac esac
done done
@@ -441,25 +441,30 @@ _get_completer() {
local curr_arg local curr_arg
curr_arg=${COMP_WORDS[COMP_CWORD]} curr_arg=${COMP_WORDS[COMP_CWORD]}
if [[ $COMP_CWORD -eq 1 ]]; then if [[ $COMP_CWORD -eq 1 ]]; then
COMPREPLY=( $(compgen -W "help autocomplete l list c copy p paste delete Delete" -- $curr_arg ) ); COMPREPLY=( $(compgen -W "help autocomplete l list c copy p paste delete Delete" -- "$curr_arg" ) );
fi fi
if [[ $COMP_CWORD -eq 2 ]]; then if [[ $COMP_CWORD -eq 2 ]]; then
case ${COMP_WORDS[$(( $COMP_CWORD - 1 ))]} in case ${COMP_WORDS[1]} in
p|paste|d*|e|edit|rm|remove) d*|e|edit|rm|remove)
local IFS=$'"'"'\n'"'"' local IFS=$'"'"'\n'"'"'
local remotelist=( $( eval CCLIP_EXEC simplelist ) ) local remotelist=( $( eval CCLIP_EXEC simplelist ) )
COMPREPLY=( $(compgen -W "${remotelist[*]}" -- $curr_arg ) ); COMPREPLY=( $(compgen -W "${remotelist[*]}" -- "$curr_arg" ) );
;;
p|paste)
local IFS=$'"'"'\n'"'"'
local remotelist=( $( eval CCLIP_EXEC simplelist ) )
COMPREPLY=( $(compgen -W "${remotelist[*]}" -- "$curr_arg" ) );
;; ;;
c*) c*)
COMPREPLY=( $(compgen -f -d -X '' -- $curr_arg ) ); COMPREPLY=();
;; ;;
esac esac
fi fi
} }
complete -F _CCLIP_EXEC_complete CCLIP_EXEC complete -o bashdefault -o default -o nospace -F _CCLIP_EXEC_complete CCLIP_EXEC
# Run me as: source <( CCLIP_EXEC autocomplete ) # Run me as: source <( CCLIP_EXEC autocomplete )
' | sed "s,CCLIP_EXEC,$self,g" ' | sed "s,CCLIP_EXEC,$self,g"
exit 0 exit 0
} }
_qCol() { _qCol() {