summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/byo6
-rwxr-xr-xbin/gauth4
-rwxr-xr-xbin/icat40
-rwxr-xr-xbin/open11
-rwxr-xr-xbin/vimki33
-rwxr-xr-xbin/xt3
6 files changed, 72 insertions, 25 deletions
diff --git a/bin/byo b/bin/byo
index 389e112..bc09fb8 100755
--- a/bin/byo
+++ b/bin/byo
@@ -2,7 +2,7 @@
# Backup to yoda
[ "$USER" = root ] || exec sudo "$0" "$@"
-usage='Usage: byo [-cdk]
+usage='Usage: byo [-cdk] [/dev/sda2]
Backup local disk to yoda external disk.
Options:
@@ -19,10 +19,12 @@ while getopts :Ccdk opt; do
done
shift $((OPTIND - 1))
+dev=$1
yoda_uuid='8c463221-6bb7-414e-9060-c9570bb3a6bb'
+[ "$dev" ] || dev=$(blkid --uuid "$yoda_uuid")
dest=/mnt/backup/$(hostname)
-[ -b /dev/mapper/yoda ] && noclose=1 || cryptsetup open "$(blkid --uuid "$yoda_uuid")" yoda
+[ -b /dev/mapper/yoda ] && noclose=1 || cryptsetup open "$dev" yoda
findmnt /dev/mapper/yoda /mnt >/dev/null && noumount=1 || mount /dev/mapper/yoda /mnt
time backup -v -d "$dest"
[ ! "$optC" ] || backup -v -d "$dest" clean
diff --git a/bin/gauth b/bin/gauth
index 575d6fc..699cd84 100755
--- a/bin/gauth
+++ b/bin/gauth
@@ -1,7 +1,9 @@
#!/bin/sh
# Use backup from andOTP
-gpg -qd ~/.otp_accounts.json.gpg |
+#gpg -qd ~/otp_accounts.json.gpg.pgp |
+#gpg -qd ~/.otp_accounts.json.gpg |
+cat ~/otp_accounts.json |
jq -r '.[] | "\(.label) \(.secret)"' |
while read -r l s; do
echo "$l $(oathtool --totp -b "$s")"
diff --git a/bin/icat b/bin/icat
index 702d648..d363e09 100755
--- a/bin/icat
+++ b/bin/icat
@@ -1,10 +1,12 @@
#!/bin/sh -e
# Display images directly in terminal.
-# Tested with xterm v361
+# Tested with xterm v361. Depends on imagemagick convert(1).
+
+[ "$LC_TERMINAL" = iTerm2 ] && [ -x "$HOME/.iterm2/imgcat" ] && exec "$HOME/.iterm2/imgcat" "$@"
# maxsize prints the geomtry size of terminal window, with
# a maximum value of 1000 pixels for width and height, or
-# 640x480 if size can not be probed.
+# 640x480 if terminal size can not be probed.
maxsize() {
[ "$WINDOWID" ] || { echo "640x480>"; return; }
xwininfo -id "$WINDOWID" | {
@@ -19,10 +21,42 @@ maxsize() {
}
}
+clearline() { printf "\r \r"; }
+
+ms=$(maxsize)
+
# Use convert(1) from imagemagick to output sixel format.
# -flatten uses the terminal background color as transparent layer
# -resize use the terminal size as bounding box, with a limit of 1000 pixels
# image is not resized if smaller than limit
#exec convert -resize "$(maxsize)>" -transparent-color white -flatten -- ${1:--} sixel:-
# color #rrrrggggbbbb
-exec convert -resize "$(maxsize)>" -- ${1:--} sixel:${2:--}
+#exec convert -resize "$(maxsize)>" -- ${1:--} sixel:${2:--}
+
+put=:
+while getopts :cpv opt; do
+ case $opt in
+ (c) clear=1 ;;
+ (p) pause=1 put=printf ;;
+ (v) put=printf ;;
+ (*) echo "Usage: icat [-cpv] [image_file ...]"; exit 1 ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+[ "$#" = 0 -o "$#" = 1 -a "$1" = - ] && {
+ convert -resize "$ms>" - sixel:-
+ exit
+}
+
+for f; do
+ $put "Next: %s" "$f"
+ [ "$pause" ] && {
+ read -sr
+ [ "$REPLY" = s ] && clearline && continue
+ }
+ [ "$clear" ] && clear
+ clearline
+ $put "%s\n" "$f"
+ convert -resize "$ms>" -- "$f" sixel:-
+done
diff --git a/bin/open b/bin/open
deleted file mode 100755
index 0fa97a7..0000000
--- a/bin/open
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/sh
-
-exec >/tmp/open.out 2>&1
-set -x
-
-cmd=xdg-open
-case $1 in
-(*.mkv|*.mp4) cmd=vlc;;
-esac
-
-exec $cmd "$@"
diff --git a/bin/vimki b/bin/vimki
index af5c58c..e3e0f4d 100755
--- a/bin/vimki
+++ b/bin/vimki
@@ -4,14 +4,33 @@
# rename changes the link name and propagates the change in the wiki
rename1() {
+ [ "$(head -c 8 "$3")" = VimCrypt ] && return
gawk -v old="$1" -v new="$2" -v IGNORECASE=1 '
{
gsub("[[]" old "[]]", "[" new "]")
print
}
- ' "$3"
+ ' "$3" > "$3.$$" && mv "$3.$$" "$3"
}
+link2rx() {
+ gawk -v rx="$1" -v IGNORECASE=1 '
+ BEGIN {
+ gsub(/_/, "\\W+", rx)
+ gsub(/a/, "[aåäáàâã]", rx)
+ gsub(/c/, "[cç]", rx)
+ gsub(/e/, "[eéèêë]", rx)
+ gsub(/i/, "[iîíìï]", rx)
+ gsub(/o/, "[oôöóõò]", rx)
+ gsub(/u/, "[uùûüú]", rx)
+ gsub(/y/, "[yÿ]", rx)
+ gsub(/n/, "[nñ]", rx)
+ print rx
+ }'
+}
+
+#shellcheck disable=SC2020
+
linkfile() {
echo "$1" |
tr '[:upper:]' '[:lower:]' |
@@ -20,11 +39,11 @@ linkfile() {
}
rename() {
- for f in *; do
- rename1 "$1" "$2" "$f" > "$f.$$" && mv "$f.$$" "$f"
- done
- oldf="$(linkfile "$1")"
- [ -f "$oldf" ] && mv "$oldf" "$(linkfile "$2")"
+ rx=$(link2rx "$1")
+ # Parallelize renaming
+ echo *.md | xargs -n 1 -P 8 "$0" rename1 "$rx" "$2"
+ oldf="$(linkfile "$1").md"
+ [ -f "$oldf" ] && mv "$oldf" "$(linkfile "$2").md"
}
fixfiles() {
@@ -33,5 +52,5 @@ fixfiles() {
done
}
-cd ~/Wiki
+cd ~/Wiki || exit
"$@"
diff --git a/bin/xt b/bin/xt
index 71b92d3..9395b3e 100755
--- a/bin/xt
+++ b/bin/xt
@@ -1,4 +1,5 @@
#!/bin/sh
-exec xterm -sl 500 -j -cr red "$@" &
+#exec xterm -sl 500 -j -cr red "$@" &
+exec xterm "$@" &
#cmd="urxvtc ${@:--T $HOSTNAME}"
#eval "$cmd" || { [ $? = 2 ] && urxvtd -q -o -f && eval "$cmd"; }