From 7e8d39871c9adab7cc492460337df3aab5fe8008 Mon Sep 17 00:00:00 2001 From: Nick Patavalis Date: Sat, 10 Feb 2018 13:11:04 +0200 Subject: [PATCH] Cleanups --- bash_completion/picocom | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/bash_completion/picocom b/bash_completion/picocom index 7daa621..eb1bab7 100644 --- a/bash_completion/picocom +++ b/bash_completion/picocom @@ -48,10 +48,10 @@ # _picocom_split_line # -# Splits line into words. Line is split in almost exatcly the same way +# Splits line into words. Splits line in almost exatcly the same way # as readline does it. Using this function, you can specify your own -# delimiter and separator characters without having to mess with -# COMP_WORDBREAKS (which may affect other completion functions / +# delimiter and separator characters without having to change +# COMP_WORDBREAKS (which may affect other completion functions and # scripts). In addtion, this function takes into account COMP_POINT # and splits up to it, which may help when completing to the middle of # an argument. @@ -196,10 +196,11 @@ function _picocom_split_line() words+=( "$word" ) } +# Remove quotes from $1. _picocom_dequote() { local quoted="$1" - local word i inside + local i c c1 inside word for (( i=0; i<${#quoted}; i++ )); do c=${quoted:i:1} @@ -219,7 +220,7 @@ _picocom_dequote() continue fi elif [[ $inside == '"' ]]; then - if [[ $c == '\' ]]; then + if [[ $c == '\' && $c1 = [\\\"\$\`] ]]; then let i++ c=$c1 elif [[ $c == '"' ]]; then @@ -232,6 +233,7 @@ _picocom_dequote() echo "$word" } +# Remove character mappings that already appear in $cur _picocom_filter_mappings() { local IFS cur1 m c found @@ -304,7 +306,7 @@ _picocom() echo > $DEBUG echo "$prev | $cur | " > $DEBUG - # Handle option values given with "=" or "==" + # Handle option values given with "=" if [[ $cur =~ "="+ ]]; then _picocom_is_opt "$prev" && cur= fi @@ -314,7 +316,7 @@ _picocom() case "$prev" in -v | --receive-cmd | -s | --send-cmd) - # nothing special, just default completion + # nothing special, do default completion return 0 ;; -I | --imap | -O | --omap | -E | --emap ) @@ -322,10 +324,10 @@ _picocom() _picocom_filter_mappings cur1=${cur##*[, ]} cur0=${cur%"$cur1"} - echo "$cur0 | $cur1 |" > $DEBUG + #echo "$cur0 | $cur1 |" > $DEBUG local IFS=$'\n' COMPREPLY=( $(compgen -P "$cur0" -S "," -W "${mapfilt[*]}" -- "$cur1") ) - echo "${COMPREPLY[*]}" > $DEBUG + #echo "${COMPREPLY[*]}" > $DEBUG if [[ ${#COMPREPLY[@]} -ne 0 ]]; then compopt -o nospace # This only works for bash-4.4 and newer @@ -334,7 +336,7 @@ _picocom() return 0 ;; -e | --escape) - # nothing special, just default completion + # nothing special, do default completion return 0 ;; -f | --flow) @@ -362,22 +364,22 @@ _picocom() return 0 ;; -g | --logfile) - # nothing special, just default completion + # nothing special, do default completion return 0 ;; -t | --initstring) - # nothing special, just default completion + # nothing special, do default completion return 0 ;; -x | --exit-after) - # nothing special, just default completion + # nothing special, do default completion return 0 ;; *) ;; esac - if [[ ${cur} == -* ]] ; then + if [[ $cur == -* ]] ; then COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") ) # This only works for bash 4.4 and newer compopt -o nosort > /dev/null 2>&1