From 947f7df73f16981f170265a64a964142fc617023 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Thu, 20 Jun 2024 12:01:39 +0200 Subject: checkpoint --- bin/common/gt | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100755 bin/common/gt (limited to 'bin/common') diff --git a/bin/common/gt b/bin/common/gt new file mode 100755 index 0000000..bdbd00f --- /dev/null +++ b/bin/common/gt @@ -0,0 +1,111 @@ +#!/bin/sh + +# Git Trach, track the state of multiple repos from a single file. + +# dependencies: +# - git +# - $EDITOR: -e +# - herbe (optional): -s + +repos="${XDG_DATA_HOME:-$HOME}"/git-track.txt +touch "$repos" + +help() { + >&2 cat </dev/null | while read -r line + # \r\033[0K : clear current line + do >&2 printf '\r\033[0K%s' "$line" + done +} + +# Print repositories prettily +# This function function prints animations (eg. clearing the line) +# to stderr and the final status line is outputted to stdout. +status() { + while read -r repo + do + repo_pretty="$(printf '%s' "$repo" | sed "s@$HOME@~@" )" + + # absolute path + cd "$repo" + + # replace line with status + >&2 printf '\r\033[0K' + + status="$(git status --porcelain 2> /dev/null | awk '{print $1}' | uniq | tr -d '\n')" + remote="$(git branch -v 2>/dev/null | sed 's/ahead/↑/;s/behind/↓/;s/[^↓↑]*//g')" + + printf '%s %s %s\n' "$repo_pretty" "$status" "$remote" + done < "$repos" +} + +# run git command in each repo +# $1: command +repos_cmd() { + while read -r repo + do + repo_pretty="$(printf '%s' "$repo" | sed "s@$HOME@~@" )" + printf ''\''%s'\'' in %s' "$1" "$repo_pretty" + ( + cd "$repo" + git "$1" > /dev/null 2>&1 + [ $? -gt 0 ] && s="x" || s="o" + printf '\r\033[0K%s: %s\n' "$repo_pretty" "$s" + ) + done < "$repos" +} + +# no options +if [ -z "$1" ] +then + help + exit 1 +fi + +while getopts ":a:c:f:lshe" opt +do + case "$opt" in + a) + cd "$OPTARG" || exit 1 + r="$(git rev-parse --show-toplevel)" + [ "$r" ] || exit 2 + + if grep "$r" "$repos" > /dev/null 2>&1 + then + >&2 printf 'added already.\n' + exit 2 + fi + + printf '%s\n' "$r" >> "$repos" + + >&2 printf 'added.\n' ;; + c) repos_cmd "$OPTARG" ;; + s) status=1 ;; + l) cat "$repos" ;; + e) $EDITOR "$repos" ;; + f) repos="$OPTARG" ;; + T) help ;; + :) >&2 printf -- '-%s requires argument\n' "$OPTARG"; exit 1 ;; + ?) >&2 printf -- 'Invalid option: -%s\n' "$OPTARG"; exit 1 ;; + esac +done + +if [ "$status" ] +then + status + which herbe > /dev/null 2>&1 && + eval "herbe $(status | sed 's/"/\"/g;s/.*/"&"/' | tr '\n' ' ')" & +fi -- cgit v1.2.3 From cbbaf8cb1e3e0f8113104d8234bb479430f27dff Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Thu, 20 Jun 2024 12:15:46 +0200 Subject: checkpoint --- bin/common/gt | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'bin/common') diff --git a/bin/common/gt b/bin/common/gt index bdbd00f..53d2cab 100755 --- a/bin/common/gt +++ b/bin/common/gt @@ -7,7 +7,8 @@ # - $EDITOR: -e # - herbe (optional): -s -repos="${XDG_DATA_HOME:-$HOME}"/git-track.txt +repos=$HOME/sync/share/git-track.txt +# prevent file not found errors touch "$repos" help() { @@ -92,18 +93,27 @@ do printf '%s\n' "$r" >> "$repos" >&2 printf 'added.\n' ;; - c) repos_cmd "$OPTARG" ;; - s) status=1 ;; + c) f_command=1; f_arg="$OPTARG" ;; + s) f_status=1 ;; l) cat "$repos" ;; e) $EDITOR "$repos" ;; f) repos="$OPTARG" ;; - T) help ;; + h) help ;; :) >&2 printf -- '-%s requires argument\n' "$OPTARG"; exit 1 ;; ?) >&2 printf -- 'Invalid option: -%s\n' "$OPTARG"; exit 1 ;; esac done -if [ "$status" ] +# commands hereafter must happen in order + +[ "$(wc -l < "$repos")" -gt 0 ] || exit 0 + +if [ "$f_command" ] +then + repos_cmd "$f_arg" +fi + +if [ "$f_status" ] then status which herbe > /dev/null 2>&1 && -- cgit v1.2.3 From f3ca3f8988c2af29c8d13b5336d1bfefb3e36c81 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Thu, 20 Jun 2024 12:46:19 +0200 Subject: fix error on multiple branches --- bin/common/gt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'bin/common') diff --git a/bin/common/gt b/bin/common/gt index 53d2cab..c679b23 100755 --- a/bin/common/gt +++ b/bin/common/gt @@ -5,7 +5,6 @@ # dependencies: # - git # - $EDITOR: -e -# - herbe (optional): -s repos=$HOME/sync/share/git-track.txt # prevent file not found errors @@ -47,7 +46,8 @@ status() { >&2 printf '\r\033[0K' status="$(git status --porcelain 2> /dev/null | awk '{print $1}' | uniq | tr -d '\n')" - remote="$(git branch -v 2>/dev/null | sed 's/ahead/↑/;s/behind/↓/;s/[^↓↑]*//g')" + remote="$(git branch -v 2>/dev/null | + sed '/^*/!d;s/ahead/↑/;s/behind/↓/;s/[^↓↑]*//g')" printf '%s %s %s\n' "$repo_pretty" "$status" "$remote" done < "$repos" @@ -116,6 +116,6 @@ fi if [ "$f_status" ] then status - which herbe > /dev/null 2>&1 && - eval "herbe $(status | sed 's/"/\"/g;s/.*/"&"/' | tr '\n' ' ')" & fi + +# eval "herbe $(status | sed 's/"/\"/g;s/.*/"&"/' | tr '\n' ' ')" -- cgit v1.2.3 From 3145010306902a8b9e0a5863527837aa963afef5 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Fri, 21 Jun 2024 22:37:33 +0200 Subject: checkpoint --- bin/common/askpass | 13 +++++++++++++ bin/menuscripts/mpass | 2 +- config/essentials/shell/functions.sh | 14 -------------- config/essentials/vis/visrc.lua | 21 ++++++++++++++++++++- config/home/.zshenv | 3 +++ 5 files changed, 37 insertions(+), 16 deletions(-) create mode 100755 bin/common/askpass (limited to 'bin/common') diff --git a/bin/common/askpass b/bin/common/askpass new file mode 100755 index 0000000..2725dbf --- /dev/null +++ b/bin/common/askpass @@ -0,0 +1,13 @@ +#!/bin/sh + +# We can figure out the password for the key based on $1 +# which is in the following form: +# Enter passphrase for key 'path/to/key': +# The point is to retrieve the path and use the final name of the key +# find the according password. +key="$(printf '%s\n' "$1" | + cut -f 2 -d \' | + awk -F '/' '{print $NF}')" +pass="keys/$(hostname)/ssh/$key" + +pass show "$pass" | head -n 1 diff --git a/bin/menuscripts/mpass b/bin/menuscripts/mpass index 7348321..f513b16 100755 --- a/bin/menuscripts/mpass +++ b/bin/menuscripts/mpass @@ -14,7 +14,7 @@ list_pswds() while [ -d "$store/$file" ] do - choice="$(list_pswds "$store/$file" | dmenu -c -g 4 -l 4)" + choice="$(list_pswds "$store/$file" | commander -c)" [ "$choice" ] || exit 1 [ -z "$file" ] && file="$choice" || file="$file/$choice" done diff --git a/config/essentials/shell/functions.sh b/config/essentials/shell/functions.sh index 1b69fbd..27eb33e 100644 --- a/config/essentials/shell/functions.sh +++ b/config/essentials/shell/functions.sh @@ -364,17 +364,3 @@ ffconcat () { ffmpeg -y -f concat -safe 0 -i $tmp -c copy "$1" rm $tmp } - -# wrap ssh and add key if exists -ssh() { - if [ "$#" -gt 1 ] - then - /usr/bin/ssh $@ - return - fi - - grep -E "Host\s+$1" $HOME/.ssh/config > /dev/null 2>&1 && - keyadd "$1" > /dev/null 2>&1 - /usr/bin/ssh "$1" -} - diff --git a/config/essentials/vis/visrc.lua b/config/essentials/vis/visrc.lua index 7847784..e35b436 100644 --- a/config/essentials/vis/visrc.lua +++ b/config/essentials/vis/visrc.lua @@ -125,9 +125,28 @@ vis.events.subscribe(vis.events.WIN_OPEN, function(win) -- luacheck: no unused a if win.syntax == "bash" then map_keys( m.NORMAL, - " v", + ";p", "V:x/^(\\s*)(.+)$/ c/\\1>\\&2 printf '\\2: %s\\\\n' \"$\\2\"/", "Print variable" ) + map_keys( + m.NORMAL, + ";v", + "V:x/^(\\s*)(.+)$/ c/\\1\"$(\\2)\"/", + "Surround in variable" + ) + map_keys( + m.NORMAL, + ";|", + "V:x/\\| / c/|\n\t/", + "Wrap one-line multi pipe command" + ) + map_keys( + m.NORMAL, + ";e", + "V:x/^(\\s*)(.+)$/ c/\\1[ \"\\2\" ] || exit 1/", + "Condition exit if empty" + ) + end end) diff --git a/config/home/.zshenv b/config/home/.zshenv index a87f01d..34a7c2f 100644 --- a/config/home/.zshenv +++ b/config/home/.zshenv @@ -96,3 +96,6 @@ export PATH="$PATH:$GOPATH/bin" export PLAN9=/usr/lib/plan9 export PATH="$PATH:$PLAN9/bin" + +export SSH_ASKPASS=askpass +export SSH_ASKPASS_REQUIRE=prefer -- cgit v1.2.3