From 1c39c97e8c416ba33aa3ae884354966609c84476 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Fri, 22 Dec 2023 17:18:34 +0100 Subject: Add GPLv3 license and INSTALL --- INSTALL | 7 +++++++ compl/crypt.bash | 53 ----------------------------------------------------- compl/crypt.zsh | 13 ------------- extra/crypt.bash | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ extra/crypt.zsh | 13 +++++++++++++ 5 files changed, 73 insertions(+), 66 deletions(-) create mode 100644 INSTALL delete mode 100755 compl/crypt.bash delete mode 100755 compl/crypt.zsh create mode 100755 extra/crypt.bash create mode 100755 extra/crypt.zsh diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..f13f020 --- /dev/null +++ b/INSTALL @@ -0,0 +1,7 @@ +To install crypt you can simply rename `crypt.sh` to `crypt` and move it in your path. +For example by doing + sudo cp crypt.sh /usr/bin/crypt + +Similarly, to install the autocomplete scripts you can do something like + sudo cp extra/crypt.bash /usr/share/bash-completion/completions/crypt + sudo cp extra/crypt.zsh /usr/share/zsh/site-functions/_crypt diff --git a/compl/crypt.bash b/compl/crypt.bash deleted file mode 100755 index 3074ff5..0000000 --- a/compl/crypt.bash +++ /dev/null @@ -1,53 +0,0 @@ -# Bash completion -# -# Copy to /usr/share/bash-completion/completions/crypt - -_crypt() { - COMPREPLY=() - - local location="${CRYPT_PATH:-$HOME/.crypt}" - location="${location%/}/" - local cur="${COMP_WORDS[COMP_CWORD]}" - - local IFS=$'\n' - local suffix=".gpg" - - local firstitem="" - local i=0 item - local items=($(compgen -f $location$cur)) - - for item in ${items[@]}; do - [[ $item =~ /\.[^/]*$ ]] && continue - - if [[ ${#items[@]} -eq 1 ]]; then - while [[ -d $item ]]; do - local subitems=($(compgen -f "$item/")) - local filtereditems=( ) item2 - for item2 in "${subitems[@]}"; do - [[ $item2 =~ /\.[^/]*$ ]] && continue - filtereditems+=( "$item2" ) - done - if [[ ${#filtereditems[@]} -eq 1 ]]; then - item="${filtereditems[0]}" - else - break - fi - done - fi - - [[ -d $item ]] && item="$item/" - - item="${item%$suffix}" - COMPREPLY+=("${item#$location}") - if [[ $i -eq 0 ]]; then - firstitem=$item - fi - let i+=1 - done - - if [[ $i -gt 1 || ( $i -eq 1 && -d $firstitem ) ]]; then - compopt -o nospace - fi -} - -complete -o filenames -F _crypt crypt diff --git a/compl/crypt.zsh b/compl/crypt.zsh deleted file mode 100755 index 2e1e57a..0000000 --- a/compl/crypt.zsh +++ /dev/null @@ -1,13 +0,0 @@ -#compdef crypt -#autoload - -# copy to /usr/share/zsh/site-functions/_crypt - -_crypt() { - local IFS=$'\n' - local location - zstyle -s ":completion:${curcontext}:" location location || location="${CRYPT_PATH:-$HOME/.crypt}" - _values -C 'entries' ${$(crypt list --plain | sed -e "s#\([^[:space:]]*\)[[:space:]]*\(.*\)#\1\[\2\]#g" | sort):-""} -} - -_crypt diff --git a/extra/crypt.bash b/extra/crypt.bash new file mode 100755 index 0000000..3074ff5 --- /dev/null +++ b/extra/crypt.bash @@ -0,0 +1,53 @@ +# Bash completion +# +# Copy to /usr/share/bash-completion/completions/crypt + +_crypt() { + COMPREPLY=() + + local location="${CRYPT_PATH:-$HOME/.crypt}" + location="${location%/}/" + local cur="${COMP_WORDS[COMP_CWORD]}" + + local IFS=$'\n' + local suffix=".gpg" + + local firstitem="" + local i=0 item + local items=($(compgen -f $location$cur)) + + for item in ${items[@]}; do + [[ $item =~ /\.[^/]*$ ]] && continue + + if [[ ${#items[@]} -eq 1 ]]; then + while [[ -d $item ]]; do + local subitems=($(compgen -f "$item/")) + local filtereditems=( ) item2 + for item2 in "${subitems[@]}"; do + [[ $item2 =~ /\.[^/]*$ ]] && continue + filtereditems+=( "$item2" ) + done + if [[ ${#filtereditems[@]} -eq 1 ]]; then + item="${filtereditems[0]}" + else + break + fi + done + fi + + [[ -d $item ]] && item="$item/" + + item="${item%$suffix}" + COMPREPLY+=("${item#$location}") + if [[ $i -eq 0 ]]; then + firstitem=$item + fi + let i+=1 + done + + if [[ $i -gt 1 || ( $i -eq 1 && -d $firstitem ) ]]; then + compopt -o nospace + fi +} + +complete -o filenames -F _crypt crypt diff --git a/extra/crypt.zsh b/extra/crypt.zsh new file mode 100755 index 0000000..2e1e57a --- /dev/null +++ b/extra/crypt.zsh @@ -0,0 +1,13 @@ +#compdef crypt +#autoload + +# copy to /usr/share/zsh/site-functions/_crypt + +_crypt() { + local IFS=$'\n' + local location + zstyle -s ":completion:${curcontext}:" location location || location="${CRYPT_PATH:-$HOME/.crypt}" + _values -C 'entries' ${$(crypt list --plain | sed -e "s#\([^[:space:]]*\)[[:space:]]*\(.*\)#\1\[\2\]#g" | sort):-""} +} + +_crypt -- cgit v1.2.3