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