From 04029c520f4cd1c7fbf9444e6ba5304b632d23f4 Mon Sep 17 00:00:00 2001 From: Karel Kočí Date: Mon, 18 Sep 2017 20:20:01 +0200 Subject: Add completions for gitbmerge --- bashrc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'bashrc') diff --git a/bashrc b/bashrc index ef4e60c..aee1c22 100644 --- a/bashrc +++ b/bashrc @@ -37,3 +37,27 @@ case "$TERM" in ;; esac +# Completions ################################################## + +# Some completion functions +_gitbmerge() { + local cur prev + _init_completion || return + [ $COMP_CWORD -gt 1 ] && return # Complete only single dependency + COMPREPLY=() + local GDIR="$(pwd)" + while [ ! -d "$GDIR/.git" ]; do + [ -z "$GDIR" ] && return + GDIR="${GDIR%/*}" + done + GDIR="$GDIR/.git" + [ -f "$GDIR" ] && GDIR="$(cat "$GDIR")" # This just points to some other directory + [ -d "$GDIR/refs/heads" ] || return # No completion if there is no local branch + local ops="" + for B in "$GDIR"/refs/heads/*; do + # TODO skip branch on HEAD + ops="$ops ${B#$GDIR/refs/heads/}" + done + COMPREPLY+=($(compgen -W "${ops}" -- ${cur})) +} +complete -F _gitbmerge gitbmerge -- cgit v1.3 From 39da53ab62b710a231cef8cea50bfa316816f2ad Mon Sep 17 00:00:00 2001 From: Karel Kočí Date: Mon, 18 Sep 2017 21:04:04 +0200 Subject: Add completions for usbkey --- bash_completions/usbkey | 35 +++++++++++++++++++++++++++++++++++ bashrc | 8 ++++++++ install | 4 ++++ zsh_completions/usbkey | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ zshrc | 1 + 5 files changed, 96 insertions(+) create mode 100644 bash_completions/usbkey create mode 100644 zsh_completions/usbkey (limited to 'bashrc') diff --git a/bash_completions/usbkey b/bash_completions/usbkey new file mode 100644 index 0000000..10cb0b9 --- /dev/null +++ b/bash_completions/usbkey @@ -0,0 +1,35 @@ +# Bash completion file for usbkey +# vim: ft=sh + +_usbkey_mounted() { + mount | grep "/media/usbkey" | grep -q "/dev/mapper/usbkey" +} + +_usbkey() { + local cur prev + _init_completion || return + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + if [[ $COMP_CWORD -gt 1 ]]; then + _usbkey_mounted || return + case "${COMP_WORDS[1]}" in + ssh-import) + [ -d "/media/usbkey/ssh" ] || return + local keys + for F in $(find "/media/usbkey/ssh" -name '*.pub'); do + F="${F#/media/usbkey/ssh/}" + keys="$keys ${F%.pub}" + done + COMPREPLY+=($(compgen -W "${keys}" -- ${cur})) + ;; + esac + else + local ops="-h --help mount sync" + if _usbkey_mounted; then + ops="$ops unmount ssh-list ssh-generate ssh-import" + fi + COMPREPLY+=($(compgen -W "${ops}" -- ${cur})) + fi +} + +complete -F _usbkey usbkey diff --git a/bashrc b/bashrc index aee1c22..a5462d5 100644 --- a/bashrc +++ b/bashrc @@ -10,6 +10,14 @@ if [ -f /etc/bashrc ]; then . /etc/bashrc fi +# Source all completions +if [ -d ~/.bash_completions ]; then + for F in $(find ~/.bash_completions -type f); do + . "$F" + done +fi + +# PROMPT ####################################################### PS1='$( if [ `id -u` -eq "0" ]; then echo -n "\[\e[1;31m\]\u@\h:\[\e[1;34m\]\W\[\e[1;31m\]\$\[\e[0m\] " diff --git a/install b/install index c6b769e..549f63f 100755 --- a/install +++ b/install @@ -22,12 +22,14 @@ if ask "Install Bashrc"; then inst bashrc ~/.bashrc inst shellrc ~/.shellrc inst profile ~/.profile + mkdir -p ~/.bash_completions fi if ask "Install zshrc"; then inst zshrc ~/.zshrc inst shellrc ~/.shellrc inst zprofile ~/.zprofile + mkdir -p ~/.zsh_completions fi if ask "Install GIT configuration"; then @@ -117,4 +119,6 @@ fi if ask "Install usbkey script"; then inst local/bin/usbkey ~/.local/bin/usbkey + inst zsh_completions/usbkey ~/.zsh_completions/_usbkey + inst bash_completions/usbkey ~/.bash_completions/usbkey fi diff --git a/zsh_completions/usbkey b/zsh_completions/usbkey new file mode 100644 index 0000000..0de1375 --- /dev/null +++ b/zsh_completions/usbkey @@ -0,0 +1,48 @@ +#compdef usbkey +#autoload + +_usbkey_mounted() { + mount | grep "/media/usbkey" | grep -q "/dev/mapper/usbkey" +} + +_usbkey () { + local cmd + if (( CURRENT > 2)); then + _usbkey_mounted || return + operation=${words[2]} + # Run the completion for the subcommand + case "${operation}" in + ssh-import) + [ -d "/media/usbkey/ssh" ] || return + local keys=() + for F in $(find "/media/usbkey/ssh" -name '*.pub'); do + F="${F#/media/usbkey/ssh/}" + keys+=("${F%.pub}") + done + _describe -t keys 'usbkey' keys + ;; + # TODO + esac + else + local operations=( + "mount:Mount key of usb driver" + "unmount:Unmount usb driver" + "sync:Synchronize drive to bakup drive" + ) + if _usbkey_mounted; then + operations+=( + "gpg-import:Import gpg key" + "ssh-import:Import ssh key" + "ssh-generate:Generate new ssh key" + "ssh-list:List all keys in store" + "openvpn-list:List all keys" + "openvpn-get:Get keys for some host" + "openvpn-generate:Generate key for new host" + ) + fi + _describe -t operations 'usbkey' operations + _arguments : "--help[Output help message]" + fi +} + +_usbkey diff --git a/zshrc b/zshrc index dceef1b..c8f8f31 100644 --- a/zshrc +++ b/zshrc @@ -10,6 +10,7 @@ zstyle ':completion:*' cache-path ~/.cache/zsh zstyle :compinstall filename '/home/kkoci/.zshrc' zstyle -e ':completion:*:default' list-colors 'reply=("${PREFIX:+=(#bi)($PREFIX:t)(?)*==32=33}:${(s.:.)LS_COLORS}")' zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} +fpath=(~/.zsh_completions $fpath) autoload -Uz compinit && compinit autoload -Uz colors && colors -- cgit v1.3 From 85c603b086490d5a2f78661bc1e167b11a6ea41f Mon Sep 17 00:00:00 2001 From: Karel Kočí Date: Mon, 18 Sep 2017 21:06:19 +0200 Subject: Drop unnecessary comment in bashrc --- bashrc | 1 - 1 file changed, 1 deletion(-) (limited to 'bashrc') diff --git a/bashrc b/bashrc index a5462d5..14ded1a 100644 --- a/bashrc +++ b/bashrc @@ -47,7 +47,6 @@ esac # Completions ################################################## -# Some completion functions _gitbmerge() { local cur prev _init_completion || return -- cgit v1.3 From 2fc8d93ef509f583f6977588c7b3fb2cf8ebd332 Mon Sep 17 00:00:00 2001 From: Karel Kočí Date: Thu, 5 Oct 2017 23:33:39 +0200 Subject: Drop annoyme from shell and some other small changes --- bashrc | 5 +---- shellrc | 2 +- zshrc | 11 +++-------- 3 files changed, 5 insertions(+), 13 deletions(-) (limited to 'bashrc') diff --git a/bashrc b/bashrc index 14ded1a..f36391e 100644 --- a/bashrc +++ b/bashrc @@ -22,10 +22,7 @@ PS1='$( if [ `id -u` -eq "0" ]; then echo -n "\[\e[1;31m\]\u@\h:\[\e[1;34m\]\W\[\e[1;31m\]\$\[\e[0m\] " else - if ls ~/.annoyme/*.pid 2>/dev/null >/dev/null; then - ANNOYME_PS="\[\e[1;31m\]!\[\e[0m\]" - fi - echo -n "$ANNOYME_PS\[\e[1;32m\]\u@\h:\[\e[1;34m\]\W\[\e[1;32m\]\$\[\e[0m\] " + echo -n "\[\e[1;32m\]\u@\h:\[\e[1;34m\]\W\[\e[1;32m\]\$\[\e[0m\] " fi)' PROMPT_COMMAND=' diff --git a/shellrc b/shellrc index 2979249..10f6f2c 100644 --- a/shellrc +++ b/shellrc @@ -14,7 +14,7 @@ else eval $(dircolors -b) alias make="make -j$(nproc)" fi -alias ll='ls -l' +alias ll='ls -lh' alias grep='grep --color=auto' alias git='LANG=en_GB git' alias gdb='gdb -q' diff --git a/zshrc b/zshrc index c8f8f31..ed2058d 100644 --- a/zshrc +++ b/zshrc @@ -37,14 +37,9 @@ bindkey "^[[3~" delete-char bindkey "^[3;5~" delete-char # PROMPT ####################################################### -annoyme_check() { - which annoyme >/dev/null 2>&1 && ls ~/.annoyme/*.pid 2>/dev/null >&2 && \ - echo "%{$fg_bold[red]%}!" -} - [ $UID -eq 0 ] && NCOLOR="red" || NCOLOR="green" PROMPT="%(?..%{$fg_bold[yellow]%}EXIT: %? -)\$(annoyme_check)%{$fg_bold[$NCOLOR]%}%n@%m:%{$fg_bold[blue]%}%1~%{$fg_bold[$NCOLOR]%}%(!.#.$)%{$reset_color%} " +)%{$fg_bold[$NCOLOR]%}%n@%m:%{$fg_bold[blue]%}%1~%{$fg_bold[$NCOLOR]%}%(!.#.$)%{$reset_color%} " unset NCOLOR if [ -e ~/.local/git-prompt.sh ]; then @@ -71,9 +66,9 @@ lrbell_active_window_id() { lrbell_begin() { lrbell_timestamp=$EPOCHSECONDS - lrbell_message="`pwd`: $1" if [ -n "$DISPLAY" ]; then - lrbell_window_id=$(lrbell_active_window_id) + lrbell_message="`pwd`: $1" + lrbell_window_id="$(lrbell_active_window_id)" fi } lrbell_end() { -- cgit v1.3