From 250f9c12f99c672e9f61ccd729cd28967581298e Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 7 Apr 2025 14:47:00 +0200 Subject: fix term title --- .bashrc | 4 ++-- .profile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bashrc b/.bashrc index b52782a..c24d0e0 100644 --- a/.bashrc +++ b/.bashrc @@ -26,13 +26,13 @@ OS=${OS:-$(~/bin/os)} case $OS in (arch|alpine) alias ls='ls --color=auto -v' ll='ls -AlFhv' - [ "$OS" = arch ] || trap 'printf "\e]2;${PWD/~/\~} ${BASH_COMMAND%ps1}\a"' DEBUG + [ "$OS" = arch ] || trap 'printf "\e]2;%s\a" "${BASH_COMMAND%ps1}"' DEBUG ;; (Darwin) alias ls='ls -GF' ll='ls -AlGFhv' alias ldd='otool -L' alias ibrew='arch -x86_64 /usr/local/bin/brew' - trap 'printf "\e]2;${PWD/~/\~} ${BASH_COMMAND%update_terminal_cwd}\a"' DEBUG + trap 'printf "\e]2;%s\a" " ${BASH_COMMAND%update_terminal_cwd}"' DEBUG ;; (termux) PATH=~/bin:${HOME%/*}/usr/bin:~/go/bin diff --git a/.profile b/.profile index d52b4f3..d9f225e 100644 --- a/.profile +++ b/.profile @@ -8,7 +8,7 @@ case $OS in export XDG_RUNTIME_DIR=/run/user/$(id -u) ;; (Darwin) - PATH=~/bin:~/mu/bin:/opt/homebrew/bin:/opt/homebrew/opt/ruby/bin:/opt/homebrew/opt/tcl-tk/bin:$PATH:~/go/bin:~/.cargo/bin:~/.pyenv/versions/2.7.18/bin:~/.local/bin + PATH=~/bin:~/mu/bin:/opt/homebrew/bin:/opt/homebrew/opt/python/libexec/bin:$PATH:~/go/bin:~/.cargo/bin:~/.local/bin export REPLYTO='mvertes@free.fr' export LANG=en_US.UTF-8 if [ -z "$SSH_AUTH_SOCK" ]; then -- cgit v1.2.3 From dc8fe54203e7353c5f873ef20a1b85c4c7a00b17 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Fri, 11 Apr 2025 08:27:11 +0200 Subject: update --- bin/crypt | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 bin/crypt diff --git a/bin/crypt b/bin/crypt new file mode 100755 index 0000000..01e7a31 --- /dev/null +++ b/bin/crypt @@ -0,0 +1,36 @@ +#!/bin/sh + +# (de)crypt using ssh rsa key. ed25519 not supported. + +tmp="/tmp/enc-$$" +mkdir -p "$tmp" +trap 'rm -rf $tmp' INT TERM EXIT + +# Encrypt stdin to stdout. +encrypt() { + # Generate a random 256 bits one-time key, for symmetric aes encryption. + openssl rand 32 >"$tmp/key" + + # Output the one-time key asymmetrically encrypted with the rsa pubkey. + ssh-keygen -e -f ~/.ssh/id_rsa.pub -m PKCS8 >"$tmp/pk" + openssl pkeyutl -encrypt -pubin -inkey "$tmp/pk" <"$tmp/key" + + # Now encrypt stdin to stdout, using the clear otk. + openssl aes-256-cbc -pbkdf2 -pass "file:$tmp/key" +} + +# Decrypt stdin to stdout. +decrypt() { + # The first 256 input bytes contains the one time key to be decrypted + # with the private rsa key. + dd ibs=256 count=1 iflag=direct | + openssl pkeyutl -decrypt -inkey ~/.ssh/id_rsa -out "$tmp/key" + + # The remaining input is the payload decrypted with the aes key. + openssl aes-256-cbc -d -pbkdf2 -pass "file:$tmp/key" +} + +cmd=encrypt +[ "$1" = "-d" ] && cmd=decrypt && shift +[ "$1" ] && exec 0<"$1" +"$cmd" -- cgit v1.2.3 From b7927432c7574abb47425fd1af5e7d8ab8fc936c Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Fri, 11 Apr 2025 13:33:08 +0200 Subject: improve crypt --- bin/crypt | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/bin/crypt b/bin/crypt index 01e7a31..939f3f5 100755 --- a/bin/crypt +++ b/bin/crypt @@ -1,36 +1,53 @@ #!/bin/sh -# (de)crypt using ssh rsa key. ed25519 not supported. +usage='Usage: crypt [-de] [-o output] [input] -tmp="/tmp/enc-$$" -mkdir -p "$tmp" -trap 'rm -rf $tmp' INT TERM EXIT +Encrypt or decrypt input (default: stdin) to ouput (default: stdout), +using ssh rsa key. + +Options: + -d action is decrypt (default: encrypt) + -e action is encrypt + -o output set ouput (default: stdout)' + +key="$(mktemp)" +trap 'rm -f $key' EXIT # Encrypt stdin to stdout. encrypt() { # Generate a random 256 bits one-time key, for symmetric aes encryption. - openssl rand 32 >"$tmp/key" + openssl rand 32 >"$key" + + # Convert (only once) the ssh RSA public to PKCS8, for openssl. + [ -f ~/.ssh/id_rsa.pub.pkcs8 ] || + ssh-keygen -e -f ~/.ssh/id_rsa.pub -m PKCS8 >~/.ssh/id_rsa.pub.pkcs8 # Output the one-time key asymmetrically encrypted with the rsa pubkey. - ssh-keygen -e -f ~/.ssh/id_rsa.pub -m PKCS8 >"$tmp/pk" - openssl pkeyutl -encrypt -pubin -inkey "$tmp/pk" <"$tmp/key" + openssl pkeyutl -encrypt -pubin -inkey ~/.ssh/id_rsa.pub.pkcs8 <"$key" # Now encrypt stdin to stdout, using the clear otk. - openssl aes-256-cbc -pbkdf2 -pass "file:$tmp/key" + openssl aes-256-cbc -pbkdf2 -pass "file:$key" } # Decrypt stdin to stdout. decrypt() { - # The first 256 input bytes contains the one time key to be decrypted - # with the private rsa key. - dd ibs=256 count=1 iflag=direct | - openssl pkeyutl -decrypt -inkey ~/.ssh/id_rsa -out "$tmp/key" + # Recover the aes key from the first 256 input bytes. + dd ibs=256 count=1 iflag=direct status=none | + openssl pkeyutl -decrypt -inkey ~/.ssh/id_rsa -out "$key" - # The remaining input is the payload decrypted with the aes key. - openssl aes-256-cbc -d -pbkdf2 -pass "file:$tmp/key" + # The remaining input is the payload, decrypt it with the aes key. + openssl aes-256-cbc -d -pbkdf2 -pass "file:$key" } cmd=encrypt -[ "$1" = "-d" ] && cmd=decrypt && shift -[ "$1" ] && exec 0<"$1" +while getopts :deo: opt; do + case $opt in + d) cmd=decrypt ;; + e) cmd=encrypt ;; + o) exec 1>"$OPTARG" ;; + *) echo "$usage" >&2; exit 1 ;; + esac +done +shift $((OPTIND - 1)) +[ "$1" ] && [ "$1" != "-" ] && exec 0<"$1" "$cmd" -- cgit v1.2.3 From 6b2ff5de7a85ac0dd21c4e6a3c6871099182d8ee Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Sun, 13 Apr 2025 20:03:35 +0200 Subject: cle --- .bashrc | 4 ++-- bin/cle | 42 ++++++++++++++++++++++++++++++++++++++++++ bin/crypt | 8 +++----- 3 files changed, 47 insertions(+), 7 deletions(-) create mode 100755 bin/cle diff --git a/.bashrc b/.bashrc index c24d0e0..4f1e100 100644 --- a/.bashrc +++ b/.bashrc @@ -26,13 +26,13 @@ OS=${OS:-$(~/bin/os)} case $OS in (arch|alpine) alias ls='ls --color=auto -v' ll='ls -AlFhv' - [ "$OS" = arch ] || trap 'printf "\e]2;%s\a" "${BASH_COMMAND%ps1}"' DEBUG + [ "$OS" = arch ] || trap 'printf "\e]2;%s\a" "$TERM_TAG ${BASH_COMMAND%ps1}"' DEBUG ;; (Darwin) alias ls='ls -GF' ll='ls -AlGFhv' alias ldd='otool -L' alias ibrew='arch -x86_64 /usr/local/bin/brew' - trap 'printf "\e]2;%s\a" " ${BASH_COMMAND%update_terminal_cwd}"' DEBUG + trap 'printf "\e]2;%s\a" "$TERM_TAG ${BASH_COMMAND%update_terminal_cwd}"' DEBUG ;; (termux) PATH=~/bin:${HOME%/*}/usr/bin:~/go/bin diff --git a/bin/cle b/bin/cle new file mode 100755 index 0000000..63a7153 --- /dev/null +++ b/bin/cle @@ -0,0 +1,42 @@ +#!/bin/sh -C + +clip() { print "$1" | tee /dev/tty | head -n 1 | pbcopy; } + +del() { rm -i ~/.cle/"$1"; } + +die() { echo "$@" >&2; exit 1; } + +edit() { + [ "$1" ] || die 'missing argument' + tmp=$(mktemp) f=~/.cle/"$1" + trap 'rm -f "$tmp"' EXIT + print "$1" >| "$tmp" || mkdir -p "${f%/*}" + [ -s "$tmp" ] || gen >| "$tmp" + "${EDITOR:-vim}" "$tmp" + crypt "$tmp" >| "$f" +} + +gen() { LC_ALL=C tr -dc 'A-Za-z0-9!?%=' < /dev/urandom | head -c 10; } + +list() { cd ~/.cle && find -- * -type f; } + +print() { [ -f ~/.cle/"$1" ] && crypt -d < ~/.cle/"$1"; } + +tui() { + list | fzf --preview 'cle print {}' \ + --preview-window hidden \ + --header 'ctrl-del: delete, ctrl-e: edit, ctrl-n: new' \ + --bind 'ctrl-delete:execute(cle del {})+reload(cle list)' \ + --bind 'ctrl-e:execute(cle edit {})' \ + --bind 'ctrl-n:execute(cle edit {q})+reload(cle list)' \ + --bind 'ctrl-v:toggle-preview' \ + --query "$1" --select-1 | + xargs cle clip +} + +case $1 in + (clip|del|edit|gen|list|print) + cmd=$1; shift; $cmd "$@" ;; + (*) + tui "$@" ;; +esac diff --git a/bin/crypt b/bin/crypt index 939f3f5..c63d60a 100755 --- a/bin/crypt +++ b/bin/crypt @@ -1,13 +1,12 @@ #!/bin/sh -usage='Usage: crypt [-de] [-o output] [input] +usage='Usage: crypt [-d] [-o output] [input] Encrypt or decrypt input (default: stdin) to ouput (default: stdout), using ssh rsa key. Options: -d action is decrypt (default: encrypt) - -e action is encrypt -o output set ouput (default: stdout)' key="$(mktemp)" @@ -40,14 +39,13 @@ decrypt() { } cmd=encrypt -while getopts :deo: opt; do +while getopts :do: opt; do case $opt in d) cmd=decrypt ;; - e) cmd=encrypt ;; o) exec 1>"$OPTARG" ;; *) echo "$usage" >&2; exit 1 ;; esac done shift $((OPTIND - 1)) -[ "$1" ] && [ "$1" != "-" ] && exec 0<"$1" +[ "$1" ] && exec 0<"$1" "$cmd" -- cgit v1.2.3 From 5ec6897410333a16f3ecc3f572b6d7dc490168d9 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 14 Apr 2025 10:29:17 +0200 Subject: update --- bin/cle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/cle b/bin/cle index 63a7153..b0dccbc 100755 --- a/bin/cle +++ b/bin/cle @@ -1,4 +1,4 @@ -#!/bin/sh -C +#!/bin/sh -Ce clip() { print "$1" | tee /dev/tty | head -n 1 | pbcopy; } @@ -25,11 +25,11 @@ print() { [ -f ~/.cle/"$1" ] && crypt -d < ~/.cle/"$1"; } tui() { list | fzf --preview 'cle print {}' \ --preview-window hidden \ - --header 'ctrl-del: delete, ctrl-e: edit, ctrl-n: new' \ + --header 'Ret Select, Esc Cancel, ^E Edit, ^N New, ^P Preview, ^Del Delete' \ --bind 'ctrl-delete:execute(cle del {})+reload(cle list)' \ --bind 'ctrl-e:execute(cle edit {})' \ --bind 'ctrl-n:execute(cle edit {q})+reload(cle list)' \ - --bind 'ctrl-v:toggle-preview' \ + --bind 'ctrl-p:toggle-preview' \ --query "$1" --select-1 | xargs cle clip } -- cgit v1.2.3 From 197f065a22a712d20d91862cbfb6ef4615774b4d Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Tue, 15 Apr 2025 16:09:54 +0200 Subject: update --- bin/cle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cle b/bin/cle index b0dccbc..af18e89 100755 --- a/bin/cle +++ b/bin/cle @@ -18,7 +18,7 @@ edit() { gen() { LC_ALL=C tr -dc 'A-Za-z0-9!?%=' < /dev/urandom | head -c 10; } -list() { cd ~/.cle && find -- * -type f; } +list() { cd ~/.cle && find -- * -name .git -prune -o -type f -print; } print() { [ -f ~/.cle/"$1" ] && crypt -d < ~/.cle/"$1"; } -- cgit v1.2.3 From 0616e0cc96c141a686a4a4a3c1d1391e8b43b356 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Wed, 16 Apr 2025 17:42:53 +0200 Subject: improve crypt --- bin/crypt | 60 +++++++++++++++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/bin/crypt b/bin/crypt index c63d60a..64afc42 100755 --- a/bin/crypt +++ b/bin/crypt @@ -1,51 +1,45 @@ #!/bin/sh -usage='Usage: crypt [-d] [-o output] [input] +crypt_usage='Usage: crypt [-d] [-o output] [input] -Encrypt or decrypt input (default: stdin) to ouput (default: stdout), -using ssh rsa key. +Encrypt or decrypt input (stdin) to ouput (stdout), using ssh rsa key. Options: -d action is decrypt (default: encrypt) -o output set ouput (default: stdout)' -key="$(mktemp)" -trap 'rm -f $key' EXIT - # Encrypt stdin to stdout. encrypt() { - # Generate a random 256 bits one-time key, for symmetric aes encryption. - openssl rand 32 >"$key" - - # Convert (only once) the ssh RSA public to PKCS8, for openssl. - [ -f ~/.ssh/id_rsa.pub.pkcs8 ] || - ssh-keygen -e -f ~/.ssh/id_rsa.pub -m PKCS8 >~/.ssh/id_rsa.pub.pkcs8 + set -- "$(openssl rand -hex 32)" - # Output the one-time key asymmetrically encrypted with the rsa pubkey. - openssl pkeyutl -encrypt -pubin -inkey ~/.ssh/id_rsa.pub.pkcs8 <"$key" + echo "$1" | openssl pkeyutl -encrypt -pubin -inkey /dev/fd/3 3<<- EOF + $(ssh-keygen -e -f ~/.ssh/id_rsa.pub -m PKCS8) + EOF - # Now encrypt stdin to stdout, using the clear otk. - openssl aes-256-cbc -pbkdf2 -pass "file:$key" + openssl aes-256-cbc -pbkdf2 -pass file:/dev/fd/3 3<<- EOF + $1 + EOF } # Decrypt stdin to stdout. decrypt() { - # Recover the aes key from the first 256 input bytes. - dd ibs=256 count=1 iflag=direct status=none | - openssl pkeyutl -decrypt -inkey ~/.ssh/id_rsa -out "$key" - - # The remaining input is the payload, decrypt it with the aes key. - openssl aes-256-cbc -d -pbkdf2 -pass "file:$key" + openssl aes-256-cbc -d -pbkdf2 -pass file:/dev/fd/3 3<<- EOF + $(dd ibs=256 count=1 iflag=direct status=none | + openssl pkeyutl -decrypt -inkey ~/.ssh/id_rsa) + EOF } -cmd=encrypt -while getopts :do: opt; do - case $opt in - d) cmd=decrypt ;; - o) exec 1>"$OPTARG" ;; - *) echo "$usage" >&2; exit 1 ;; - esac -done -shift $((OPTIND - 1)) -[ "$1" ] && exec 0<"$1" -"$cmd" +# Execute main only if not sourced. +if [ "${0##*/}" = "crypt" ]; then + cmd=encrypt + while getopts :do: opt; do + case $opt in + d) cmd=decrypt ;; + o) exec 1>"$OPTARG" ;; + *) echo "$crypt_usage" >&2; exit 1 ;; + esac + done + shift $((OPTIND - 1)) + [ "$1" ] && exec 0<"$1" + "$cmd" +fi -- cgit v1.2.3 From 932179c84fd566d821e05da91c4924d7cb0e591f Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Wed, 16 Apr 2025 19:25:29 +0200 Subject: update --- bin/cle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cle b/bin/cle index af18e89..1ff9dd0 100755 --- a/bin/cle +++ b/bin/cle @@ -13,7 +13,7 @@ edit() { print "$1" >| "$tmp" || mkdir -p "${f%/*}" [ -s "$tmp" ] || gen >| "$tmp" "${EDITOR:-vim}" "$tmp" - crypt "$tmp" >| "$f" + crypt < "$tmp" >| "$f" } gen() { LC_ALL=C tr -dc 'A-Za-z0-9!?%=' < /dev/urandom | head -c 10; } -- cgit v1.2.3 From ba6dd3256c9508ed0c71c7f3346d910803d54a46 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Thu, 17 Apr 2025 21:19:07 +0200 Subject: update --- .bashrc | 1 + bin/cle | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.bashrc b/.bashrc index 4f1e100..9870d56 100644 --- a/.bashrc +++ b/.bashrc @@ -51,6 +51,7 @@ export LESS=iXFRx4 # Stopwatch alias timer='echo "Timer started. Stop with Ctrl-D." && date && time cat && date' +alias fd='find . -iname' alias grep='grep -i --color' alias more='less' alias vi='vim' diff --git a/bin/cle b/bin/cle index 1ff9dd0..b26d8b7 100755 --- a/bin/cle +++ b/bin/cle @@ -2,7 +2,14 @@ clip() { print "$1" | tee /dev/tty | head -n 1 | pbcopy; } -del() { rm -i ~/.cle/"$1"; } +checkpath() { set -- $(realpath "$1"); [ "${1#~/.cle/}" != "$1" ]; } + +del() { + set -- ~/.cle/"$1" + checkpath "$1" || die "invalid path $1" + rm -i "$1" + rmdir -p "${1%/*}" 2>/dev/null || true +} die() { echo "$@" >&2; exit 1; } -- cgit v1.2.3 From 697dbbdfe606c03a36adee298c8e9081290e4d3b Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Fri, 25 Apr 2025 10:58:18 +0200 Subject: use vim for manpages --- .bashrc | 1 + .vimrc | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/.bashrc b/.bashrc index 9870d56..bd723cc 100644 --- a/.bashrc +++ b/.bashrc @@ -5,6 +5,7 @@ export PAGER=less export EDITOR=vim +export MANPAGER='vim +MANPAGER --not-a-term -' export HISTIGNORE='sudo id:uname:date:exit:df:ll:ls:ps:pwd:tc:top:history' export HISTCONTROL=ignoreboth:erasedups # no start space and duplicate entries export HISTSIZE=100000 # big big history diff --git a/.vimrc b/.vimrc index 158c3ec..640cd09 100644 --- a/.vimrc +++ b/.vimrc @@ -34,6 +34,10 @@ augroup END set guifont=6x13:h13 set guicursor=a:block-Cursor/lCursor-blinkon0 +" Activate man pages display in vim with hyperlink navigation. +ru ftplugin/man.vim +set keywordprg=:Man + " fzf plugin set rtp+=/opt/homebrew/opt/fzf let g:fzf_preview = 'cat {}' -- cgit v1.2.3 From 733d2209b0c78adaf55baf26b4aa67ef08f057ab Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Fri, 25 Apr 2025 16:49:35 +0200 Subject: update --- .vimrc | 1 + bin/cle | 50 +------------------------------------------------- 2 files changed, 2 insertions(+), 49 deletions(-) mode change 100755 => 120000 bin/cle diff --git a/.vimrc b/.vimrc index 640cd09..9c90b81 100644 --- a/.vimrc +++ b/.vimrc @@ -37,6 +37,7 @@ set guicursor=a:block-Cursor/lCursor-blinkon0 " Activate man pages display in vim with hyperlink navigation. ru ftplugin/man.vim set keywordprg=:Man +nmap q :q " fzf plugin set rtp+=/opt/homebrew/opt/fzf diff --git a/bin/cle b/bin/cle deleted file mode 100755 index b26d8b7..0000000 --- a/bin/cle +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh -Ce - -clip() { print "$1" | tee /dev/tty | head -n 1 | pbcopy; } - -checkpath() { set -- $(realpath "$1"); [ "${1#~/.cle/}" != "$1" ]; } - -del() { - set -- ~/.cle/"$1" - checkpath "$1" || die "invalid path $1" - rm -i "$1" - rmdir -p "${1%/*}" 2>/dev/null || true -} - -die() { echo "$@" >&2; exit 1; } - -edit() { - [ "$1" ] || die 'missing argument' - tmp=$(mktemp) f=~/.cle/"$1" - trap 'rm -f "$tmp"' EXIT - print "$1" >| "$tmp" || mkdir -p "${f%/*}" - [ -s "$tmp" ] || gen >| "$tmp" - "${EDITOR:-vim}" "$tmp" - crypt < "$tmp" >| "$f" -} - -gen() { LC_ALL=C tr -dc 'A-Za-z0-9!?%=' < /dev/urandom | head -c 10; } - -list() { cd ~/.cle && find -- * -name .git -prune -o -type f -print; } - -print() { [ -f ~/.cle/"$1" ] && crypt -d < ~/.cle/"$1"; } - -tui() { - list | fzf --preview 'cle print {}' \ - --preview-window hidden \ - --header 'Ret Select, Esc Cancel, ^E Edit, ^N New, ^P Preview, ^Del Delete' \ - --bind 'ctrl-delete:execute(cle del {})+reload(cle list)' \ - --bind 'ctrl-e:execute(cle edit {})' \ - --bind 'ctrl-n:execute(cle edit {q})+reload(cle list)' \ - --bind 'ctrl-p:toggle-preview' \ - --query "$1" --select-1 | - xargs cle clip -} - -case $1 in - (clip|del|edit|gen|list|print) - cmd=$1; shift; $cmd "$@" ;; - (*) - tui "$@" ;; -esac diff --git a/bin/cle b/bin/cle new file mode 120000 index 0000000..a0092cf --- /dev/null +++ b/bin/cle @@ -0,0 +1 @@ +../.cle/cle \ No newline at end of file -- cgit v1.2.3