completions
authorIan Kelling <ian@iankelling.org>
Wed, 9 Sep 2020 01:30:19 +0000 (21:30 -0400)
committerIan Kelling <ian@iankelling.org>
Wed, 9 Sep 2020 01:30:19 +0000 (21:30 -0400)
brc
brc2

diff --git a/brc b/brc
index 1e6bfb3c6c0393e7763f6f0591c58d154314591a..2ce4471764282dfe4d6d9477f1c5c92530d773c4 100644 (file)
--- a/brc
+++ b/brc
@@ -3,7 +3,6 @@
 # SPDX-License-Identifier: AGPL-3.0-or-later
 # this gets sourced. shebang is just for file mode detection
 
-
 # Use source ~/.bashrc instead of doing bash -l when running a script
 # so this can set extdebug and avoid the bash debugger.
 if [[ -s /a/bin/errhandle/err ]]; then
@@ -19,6 +18,13 @@ if shopt login_shell >/dev/null && [[ -e ~/.bash_logout ]]; then
   rm ~/.bash_logout
 fi
 
+# if [[ -s /usr/share/bash-completion/completions/git ]]; then
+#   source /usr/share/bash-completion/completions/git
+# fi
+# if [[ -s /usr/share/bash-completion/completions/gitk ]]; then
+#   source /usr/share/bash-completion/completions/gitk
+# fi
+
 # for testing error catching:
 # t2() {
 #   echo t2
@@ -34,6 +40,7 @@ fi
 
 CDPATH=.
 
+
 # remove all aliases. aliases provided by the system tend to get in the way,
 # for example, error happens if I try to define a function the same name as an alias
 unalias -a
@@ -230,8 +237,20 @@ elif [[ -s $bashrc_dir/ll-function ]]; then
 fi
 
 
+
+
 # * functions
 
+# when testing for completions, uncomment this
+# cm() { _completion_loader $1 &>/dev/null ||:; complete -p $1; }
+ccomp() {
+  local src=$1
+  shift
+  _completion_loader $src &>/dev/null ||:
+  complete -p $src &>/dev/null || return 0
+  eval $(complete -p $src | sed -r "s/ $src($| )/ $*\1/")
+}
+
 
 ..() { c ..; }
 ...() { c ../..; }
@@ -295,8 +314,6 @@ a() {
   echo -n "$x" | xclip
 }
 
-ack() { ack-grep "$@"; }
-
 b() {
   # backwards
   c -
@@ -314,6 +331,7 @@ if type -p wcd &>/dev/null; then
 else
   c() { cd "$@"; }
 fi
+ccomp cd c
 
 c4() { c /var/log/exim4; }
 
@@ -335,6 +353,7 @@ caf() {
        -exec bash -c '. ~/.bashrc; hr; echo "$1"; hr; cat "$1"' _ {} \; 2>/dev/null
 
 }
+ccomp cat cf caf
 
 calc() { echo "scale=3; $*" | bc -l; }
 # no having to type quotes, but also no command history:
@@ -348,10 +367,10 @@ cam() {
   git commit -am "$*"
 }
 
-
 ccat () { # config cat. see a config without extra lines.
   grep '^\s*[^;[:space:]#]' "$@" || [[ $? == 1 ]]
 }
+ccomp grep ccat
 
 chrbind() {
   local d
@@ -439,13 +458,13 @@ cl() {
   c =
 }
 
-d() { builtin bg; }
-complete -A stopped -P '"%' -S '"' d
-
+d() { builtin bg "$@"; }
+ccomp bg d
 
 dc() {
   diff --strip-trailing-cr -w "$@"   # diff content
 }
+ccomp diff dc
 
 despace() {
   local x y
@@ -474,6 +493,7 @@ digsort() {
     fi
   done
 }
+ccomp dig digsort
 # compare digs to the 2 servers
 # usage: digdiff @server1 @server2 DIG_ARGS
 # note: only the soa master nameserver will respond with
@@ -491,11 +511,12 @@ digdiff() {
 dt() {
   date "+%A, %B %d, %r" "$@"
 }
+ccomp date dt
 
 dus() { # du, sorted, default arg of
   du -sh ${@:-*} | sort -h
 }
-
+ccomp du dus
 
 
 e() { echo "$@"; }
@@ -530,6 +551,7 @@ ediff() {
 etail() {
   tail -F /var/log/exim4/mainlog -n 200 "$@"
 }
+ccomp tail etail
 
 # print exim old pids
 eoldpids() {
@@ -587,6 +609,7 @@ ewatchold() {
 eless() {
   less /var/log/exim4/mainlog
 }
+ccomp less eless
 eqcat() {
   exiqgrep -i | while read -r i; do
     m exim -Mvh $i
@@ -613,7 +636,7 @@ fa() {
 }
 
 faf() { # find all files. use -L to follow symlinks
-  find $@ -not \( -name .svn -prune -o -name .git -prune \
+  find "$@" -not \( -name .svn -prune -o -name .git -prune \
        -o -name .hg -prune -o -name .editor-backups -prune \
        -o -name .undo-tree-history -prune \) -type f 2>/dev/null
 }
@@ -723,7 +746,7 @@ g() {
   fi
 }
 
-# force terminal verion
+# force terminal version
 gn() {
   g -n "$@"
 }
@@ -749,7 +772,6 @@ gdkill() {
 gr() {
   grep -iIP --color=auto "$@" || return $?
 }
-
 grr() { # grep recursive
   # Don't return 1 on nonmatch because this is meant to be
   # interactive, not in a conditional.
@@ -759,6 +781,8 @@ grr() { # grep recursive
     grep --exclude-dir='*.emacs.d' --exclude-dir='*.git' -riIP --color=auto "$@" || [[ $? == 1 ]]
   fi
 }
+ccomp grep gr grr
+
 rg() {
   command rg -i -M 200 "$@"
 }
@@ -809,19 +833,7 @@ hub() {
 }
 
 i() { git "$@"; }
-# modified from ~/local/bin/git-completion.bash
-# other completion commands are mostly taken from bash_completion package
-complete -o bashdefault -o default -o nospace -F _git i 2>/dev/null \
-  || complete -o default -o nospace -F _git i
-
-if ! type service &>/dev/null; then
-  service() {
-    echo actually running: systemctl $2 $1
-    systemctl $2 $1
-  }
-fi
-
-
+ccomp git i
 
 ic() {
   # fast commit all
@@ -829,7 +841,6 @@ ic() {
 }
 
 
-
 ifn() {
   # insensitive find
   find -L . -not \( -name .svn -prune -o -name .git -prune \
@@ -860,15 +871,17 @@ l() {
   fi
 }
 
-
 lcn() { locate -i "*$**"; }
 
-lg() { LC_COLLATE=C.UTF-8 ll --group-directories-first; }
+lg() { LC_COLLATE=C.UTF-8 ll --group-directories-first "$@"; }
 
 lt() { ll -tr "$@"; }
 
 lld() { ll -d "$@"; }
 
+ccomp ls l lg lt lld ll
+
+
 low() {  # make filenames lowercase, remove bad chars
   local f new
   for f in "$@"; do
@@ -897,10 +910,10 @@ lower() { # make first letter of filenames lowercase.
 k() { # history search
   grep -iP --binary-files=text "$@" ${HISTFILE:-~/.bash_history}  | tail -n 80 || [[ $? == 1 ]];
 }
-
 ks() { # history search
   grep -P --binary-files=text "$@" ${HISTFILE:-~/.bash_history}  | uniq || [[ $? == 1 ]];
 }
+ccomp grep k ks
 
 
 make-targets() {
@@ -912,6 +925,7 @@ mkc() {
   mkdir "$1"
   c "$1"
 }
+ccomp mkdir mkc
 
 mkct() {
   mkc $(mktemp -d)
@@ -1020,6 +1034,7 @@ r() {
 rl() {
   readlink -f "$@"
 }
+ccomp readlink rl
 
 rsd() {
   # rsync, root is required to keep permissions right.
@@ -1033,13 +1048,10 @@ rsa() {
   # do not exist on the original end.
   rsync -ahvic "$@"
 }
-complete -F _rsync -o nospace rld rl rlt
-
 rst() {
   # rl without preserving modification time.
   rsync -ahvic --delete --no-t "$@"
 }
-
 rsu() { # [OPTS] HOST PATH
   # eg. rlu -opts frodo /testpath
   # relative paths will expanded with readlink -f.
@@ -1054,6 +1066,8 @@ rsu() { # [OPTS] HOST PATH
   # to keep up with unison.
   sudo rsync -rlpchviog --relative "${opts[@]}" "$path" "root@$host:/";
 }
+ccomp rsync rsd rsa rst rsu
+
 
 rmstrips() {
   ssh fencepost head -n 300 /gd/gnuorg/EventAndTravelInfo/rms-current-trips.txt | less
@@ -1075,6 +1089,7 @@ s() {
     "$@"
   fi
 }
+ccomp sudo s
 
 safe_rename() { # warn and dont rename if file exists.
   # mv -n exists, but it\'s silent
@@ -1413,6 +1428,7 @@ ssk() {
   m ssh -O exit "$@" || [[ $? == 255 ]]
   m sl "$@"
 }
+ccomp ssh sl slr sss ssk
 # plain ssh
 ssh() {
   LC_USEBASHRC=t command ssh "$@"
diff --git a/brc2 b/brc2
index ded772062b32c99df55761718c20a44f3dfa277a..92f55ec59178a8f0e44dd8c51d73349335ce9493 100644 (file)
--- a/brc2
+++ b/brc2
@@ -62,6 +62,7 @@ sle() { # sl emacs
   local f=/home/iank/.emacs.d/init.el
   sl --sl-test-cmd ". /etc/os-release ; printf %s \${VERSION//[^a-zA-Z0-9]/}; test -e $f && stat -c%Y $f" --sl-test-hook slemacs "$@"
 }
+ccomp ssh sle
 
 # Run this manually after .emacs.d changes.  Otherwise, to check if
 # files changed with find takes 90ms. sl normally only adds 25ms.  We
@@ -144,9 +145,6 @@ gnupload(){
   /a/f/gnulib/build-aux/gnupload "$@"
 }
 
-# todo, update this
-complete -F _longopt la lower low rlt rld rl lld ts ll dircp ex fcp fct fpst gr
-
 abrowserrmcompat() {
   local f
   ngset
@@ -610,8 +608,6 @@ ff() {
   fi
 }
 
-
-
 fn() {
   firefox -P alt "$@" >/dev/null 2>&1
 }
@@ -773,6 +769,7 @@ o() {
   fi
   # another alternative is run-mailcap
 }
+ccomp xdg-open o
 
 jfilter() {
   grep -Evi -e "^(\S+\s+){4}(sudo|sshd|cron)\[\S*:" \
@@ -783,7 +780,7 @@ jtail() {
 }
 jr() { journalctl "$@" | jfilter | less ; }
 jrf() { journalctl -n 200 -f "$@" | jfilter; }
-
+ccomp journalctl jtail jr jrf
 
 kff() { # keyboardio firmware flash
   pushd /a/bin/distro-setup/Arduino/Model01-Firmware
@@ -1355,8 +1352,6 @@ elif [[ -d /a ]] && [[ $PWD == "$HOME" ]] && [[ $- == *i* ]]; then
 fi
 
 
-# best practice
-unset IFS
 
 
 # for mitmproxy to get a newer python.
@@ -1413,6 +1408,9 @@ export BASEFILE_DIR=/a/bin/fai-basefiles
 # fi
 
 
+# best practice
+unset IFS
+
 # https://wiki.archlinux.org/index.php/Xinitrc#Autostart_X_at_login
 # i added an extra condition as gentoo xorg guide says depending on
 # $DISPLAY is fragile.