From 701c5bbcfc4dfb2e2af986e7eeb1f52d3c726521 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 17 Jan 2022 09:45:44 +0100 Subject: [PATCH 1/7] qutebrowser: Fix open downloads script for spaces Fixed the 'open downloads' userscript to work correctly for files with spaces in them. --- .../qutebrowser/userscripts/open_download | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/qutebrowser/.local/share/qutebrowser/userscripts/open_download b/qutebrowser/.local/share/qutebrowser/userscripts/open_download index c7763a8..4f4818c 100755 --- a/qutebrowser/.local/share/qutebrowser/userscripts/open_download +++ b/qutebrowser/.local/share/qutebrowser/userscripts/open_download @@ -16,7 +16,7 @@ # see the recent downloads, just press "sd". # # Thorsten Wißmann, 2015 (thorsten` on Libera Chat) -# Refactored to work with bemenu by Marty Oehme, 2021 (@martyo@matrix.org on Matrix) +# Marty Oehme, 2021 (@martyo@matrix.org on Matrix), refactored to work with bemenu # Any feedback is welcome! set -e @@ -25,10 +25,10 @@ set -e DOWNLOAD_DIR=${DOWNLOAD_DIR:-${QUTE_DOWNLOAD_DIR:-$HOME/downloads}} # the name of the rofi-like command if [ -n "$ROFI_CMD" ]; then - : + : elif command -v rofi >/dev/null 2>&1; then - ROFI_CMD="rofi" - ROFI_ARGS=${ROFI_ARGS:-( + ROFI_CMD="rofi" + ROFI_ARGS=${ROFI_ARGS:-( -monitor -2 # place above window -location 6 # aligned at the bottom -width 100 # use full window width @@ -39,48 +39,48 @@ elif command -v rofi >/dev/null 2>&1; then -p 'Open download:' -dmenu )} elif command -v bemenu >/dev/null 2>&1; then - ROFI_CMD="bemenu" - ROFI_ARGS="${ROFI_ARGS:--il 10}" + ROFI_CMD="bemenu" + ROFI_ARGS="${ROFI_ARGS:--il 10}" fi msg() { - local cmd="$1" - shift - local msg="$*" - if [ -z "$QUTE_FIFO" ]; then - echo "$cmd: $msg" >&2 - else - echo "message-$cmd '${msg//\'/\\\'}'" >>"$QUTE_FIFO" - fi + local cmd="$1" + shift + local msg="$*" + if [ -z "$QUTE_FIFO" ]; then + echo "$cmd: $msg" >&2 + else + echo "message-$cmd '${msg//\'/\\\'}'" >>"$QUTE_FIFO" + fi } die() { - msg error "$*" - if [ -n "$QUTE_FIFO" ]; then - # when run as a userscript, the above error message already informs the - # user about the failure, and no additional "userscript exited with status - # 1" is needed. - exit 0 - else - exit 1 - fi + msg error "$*" + if [ -n "$QUTE_FIFO" ]; then + # when run as a userscript, the above error message already informs the + # user about the failure, and no additional "userscript exited with status + # 1" is needed. + exit 0 + else + exit 1 + fi } if ! [ -d "$DOWNLOAD_DIR" ]; then - die "Download directory »$DOWNLOAD_DIR« not found!" + die "Download directory »$DOWNLOAD_DIR« not found!" fi if ! command -v "${ROFI_CMD}" >/dev/null; then - die "Rofi command »${ROFI_CMD}« not found in PATH!" + die "Rofi command »${ROFI_CMD}« not found in PATH!" fi crop-first-column() { - cut -d' ' -f2 + cut -d' ' -f2- } ls-files() { - # add the slash at the end of the download dir enforces to follow the - # symlink, if the DOWNLOAD_DIR itself is a symlink - # sort by newest - find "${DOWNLOAD_DIR}/" -maxdepth 1 -type f -printf "%T+ %f\n" | sort -r + # add the slash at the end of the download dir enforces to follow the + # symlink, if the DOWNLOAD_DIR itself is a symlink + # sort by newest + find "${DOWNLOAD_DIR}/" -maxdepth 1 -type f -printf "%T+ %f\n" | sort -r } mapfile -t entries < <(ls-files) @@ -88,14 +88,14 @@ mapfile -t entries < <(ls-files) # we need to manually check that there are items, because rofi doesn't show up # if there are no items and -no-custom is passed to rofi. if [ "${#entries[@]}" -eq 0 ]; then - die "Download directory »${DOWNLOAD_DIR}« empty" + die "Download directory »${DOWNLOAD_DIR}« empty" fi -line=$(printf '%s\n' "${entries[@]}" | - crop-first-column | - $ROFI_CMD "${ROFI_ARGS[@]}") || true +line=$(printf '%s\n' "${entries[@]}" \ + | crop-first-column \ + | $ROFI_CMD "${ROFI_ARGS[@]}") || true if [ -z "$line" ]; then - exit 0 + exit 0 fi msg info "file is $line" @@ -104,7 +104,7 @@ filetype=$(xdg-mime query filetype "$path") application=$(xdg-mime query default "$filetype") if [ -z "$application" ]; then - die "Do not know how to open »$line« of type $filetype" + die "Do not know how to open »$line« of type $filetype" fi msg info "Opening »$line« (of type $filetype) with ${application%.desktop}" From 792e0b930ad8617fe02344d42c0bb41c190cbd1b Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 28 Jan 2022 10:14:20 +0100 Subject: [PATCH 2/7] git: Development checkout also switched to Staging Using the `gcd` alias to checkout the development branch switches to, if no `development` branch is found, the `staging` branch of a repository automatically instead. --- git/.config/sh/alias.d/git.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/.config/sh/alias.d/git.sh b/git/.config/sh/alias.d/git.sh index 59ff4c3..db7df48 100644 --- a/git/.config/sh/alias.d/git.sh +++ b/git/.config/sh/alias.d/git.sh @@ -22,7 +22,7 @@ alias gcn!='git commit -v --no-edit --amend' if version_at_least 2.23 "$git_version"; then alias gcm='git switch master 2>/dev/null || git switch main' - alias gcd='git switch develop' + alias gcd='git switch develop 2>/dev/null || git switch staging' alias gcb='git switch -c' else alias gcm='git checkout master 2>/dev/null || git checkout main' From 5ee71ae705c86859915ece696e9817e2d19659f7 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 28 Jan 2022 10:15:47 +0100 Subject: [PATCH 3/7] sh: Fix graphical session start for ssh sessions The autostart function would accidentally start multiple new graphical sessions in one terminal when connected to the machine over sshd. This should fix multiple starts while keeping the old functionality and speed of checking intact. --- sh/.config/sh/profile.d/autostartx.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/sh/.config/sh/profile.d/autostartx.sh b/sh/.config/sh/profile.d/autostartx.sh index 20768cc..d4e451f 100644 --- a/sh/.config/sh/profile.d/autostartx.sh +++ b/sh/.config/sh/profile.d/autostartx.sh @@ -1,9 +1,22 @@ #!/usr/bin/env sh +# simple check for running graphical session if [ -n "$DISPLAY" ] || [ -z "$XDG_VTNR" ] || [ "$XDG_VTNR" -ne 1 ]; then - return + return +fi + +# more involved check for running graphical session +# but figures it out for weird sshd sessions as well +if [ "$(loginctl show-session "$(loginctl show-user "$(whoami)" -p Display --value)" -p Type --value)" = 'wayland' ]; then + return +fi + +# just in case we are running x11 and this wants +# to automatically start wayland, stop it from doing so +if [ "$(loginctl show-session "$(loginctl show-user "$(whoami)" -p Display --value)" -p Type --value)" = 'x11' ]; then + return fi if command -v river >/dev/null 2>&1; then - river + river fi From 572fa471ae9f9e981c8556715c328727ad5ce496 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 28 Jan 2022 10:17:26 +0100 Subject: [PATCH 4/7] nvim: Update zettelkasten mappings to new version Updated mappings for zettelkasten navigation and zettel creation to work with the changes introduced in its new update. --- nvim/.config/nvim/lua/maps.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/nvim/.config/nvim/lua/maps.lua b/nvim/.config/nvim/lua/maps.lua index f0e8278..fc655e4 100644 --- a/nvim/.config/nvim/lua/maps.lua +++ b/nvim/.config/nvim/lua/maps.lua @@ -247,10 +247,9 @@ map.v['g'] = '(dial-increment-additional)' map.v['g'] = '(dial-decrement-additional)' -- PLUGIN: zettelkasten.nvim -map.n.nore[''] = - [[:silent lua require 'zettelkasten'.open_or_make_link()]] -map.v.nore[''] = [[:lua require 'zettelkasten'.open_or_make_link(true)]] -map.n.nore['ww'] = [[:lua require 'zettelkasten'.open_index() ]] +map.n.nore[''] = [[:silent lua require 'zettelkasten'.link_follow()]] +map.v.nore[''] = [[:lua require 'zettelkasten'.link_follow(true)]] +map.n.nore['ww'] = [[:lua require 'zettelkasten'.index_open() ]] -- PLUGIN: toggleterm.nvim -- create a lazygit window, set up in toggleterm settings From ea95ca7dfab3c72d49eaeaec406ee3ae994160b5 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 28 Jan 2022 18:32:06 +0100 Subject: [PATCH 5/7] mail: Update mail-check to work with pass-coffin Updated code to be able to run a password command chosen individually, as well as a post-password command. Used in this instance to `pass open` a password store in a coffin/tomb before actually trying to read passwords out of it. --- mail/.config/isync/mbsyncrc | 4 ++-- mail/.local/bin/mail-check | 26 ++++++++++++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/mail/.config/isync/mbsyncrc b/mail/.config/isync/mbsyncrc index d6da236..cba9b9a 100644 --- a/mail/.config/isync/mbsyncrc +++ b/mail/.config/isync/mbsyncrc @@ -3,8 +3,8 @@ IMAPAccount gmail # Address to connect to Host imap.gmail.com -UserCmd "gpg2 --decrypt --no-tty --quiet --no-verbose --for-your-eyes-only --pinentry-mode ask ~/.local/share/pass/misc/aerc-gmail-app-password.gpg | grep username | cut -d: -f2" -PassCmd "gpg2 --decrypt --no-tty --quiet --no-verbose --for-your-eyes-only --pinentry-mode ask ~/.local/share/pass/misc/aerc-gmail-app-password.gpg | head -n1" +UserCmd "pass show misc/aerc-gmail-app-password | grep username | cut -d: -f2" +PassCmd "pass show misc/aerc-gmail-app-password | head -n1" # To store the password in an encrypted file use PassCmd instead of Pass # PassCmd "gpg2 -q --for-your-eyes-only --no-tty -d ~/.mailpass.gpg" # diff --git a/mail/.local/bin/mail-check b/mail/.local/bin/mail-check index c7b7577..098052b 100755 --- a/mail/.local/bin/mail-check +++ b/mail/.local/bin/mail-check @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash # # Runs mbsync, with pre-hooks and post-hooks # by default, the pre-hook first runs imapfilter @@ -38,7 +38,9 @@ # MBSYNC_NOTIFY=1 # MBSYNC_PASSWORD_FILE="/path/to/gpg/file.gpg" -PASSWORD_FILE="${MBSYNC_PASSWORD_FILE:-$HOME/.local/share/pass/misc/aerc-gmail-app-password.gpg}" +# What to run before and after decrypting the password file. +PASSWORD_CMD="pass open -t 1min" +# POST_PASSWORD_CMD="" prehook() { if [ -n "$MBSYNC_PRE" ]; then @@ -83,7 +85,7 @@ checkonline() { # warn user that he has to enter his password in a moment # to stop catching him offguard or entering something by accident checkwarnuser() { - agt=$(gpg2 --decrypt --no-tty --quiet --no-verbose --for-your-eyes-only --pinentry-mode cancel "$PASSWORD_FILE" 2>&1) + enablegpgagent if echo "$agt" | grep -qE 'No secret key'; then notify "Mail" "Password phrase needed!" sleep 2.5 @@ -91,10 +93,22 @@ checkwarnuser() { } enablegpgagent() { - ## get password from user - agt=$(gpg2 --decrypt --no-tty --quiet --no-verbose --for-your-eyes-only --pinentry-mode ask "$PASSWORD_FILE" 2>&1) + [ -n "$agt" ] && return + + if [ -n "$PASSWORD_CMD" ]; then + IFS=" " read -r -a PASSWORD_CMD <<<"$PASSWORD_CMD" + # shellcheck disable=SC2068 + agt=$(${PASSWORD_CMD[@]}) + fi + + if [ -n "$POST_PASSWORD_CMD" ]; then + IFS=" " read -r -a POST_PASSWORD_CMD <<<"$POST_PASSWORD_CMD" + "${POST_PASSWORD_CMD[@]}" + fi + ## exit program after first failed attempt - if echo "$agt" | grep -qE 'decryption failed'; then + if echo "$agt" | grep -qE 'decryption failed' || + echo "$agt" | grep -qE 'No such file'; then notify "Mail" "Process aborted." exit 1 fi From a27d86942bea658c43118f560ea3c0b79c54caeb Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sun, 30 Jan 2022 11:37:18 +0100 Subject: [PATCH 6/7] sh: Use exist program Fix sh module packages to make more extensive use of the exist program that also ships with the sh module. Simplifies intent of the code and makes it much easier to read. --- sh/.config/sh/alias | 4 ++-- sh/.config/sh/alias.d/enable-fasd-hook.sh | 2 +- sh/.config/sh/alias.d/yay.sh | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sh/.config/sh/alias b/sh/.config/sh/alias index 5746afb..9b1c9a8 100644 --- a/sh/.config/sh/alias +++ b/sh/.config/sh/alias @@ -61,6 +61,8 @@ if exist fzf; then fzf_pkg_tool=yay elif exist paru; then fzf_pkg_tool=paru + elif exist pacman; then + fzf_pkg_tool=pacman fi # shellcheck disable=2139 # we *want* this to be done at shell startup instead of dynamically if [ -n "$fzf_pkg_tool" ]; then @@ -89,6 +91,4 @@ fi if exist vifm; then alias vm=vifm alias vmm='vifm ${PWD}' - # enable picture preview script - exist vifmrun && alias vifm=vifmrun fi diff --git a/sh/.config/sh/alias.d/enable-fasd-hook.sh b/sh/.config/sh/alias.d/enable-fasd-hook.sh index 7b12527..ca239f0 100644 --- a/sh/.config/sh/alias.d/enable-fasd-hook.sh +++ b/sh/.config/sh/alias.d/enable-fasd-hook.sh @@ -1,7 +1,7 @@ #!/bin/sh # more usage instructions at https://github.com/clvv/fasd # eval "$(fasd --init posix-hook posix_alias bash-hook zsh-hook zsh-ccomp zsh-ccomp-install zsh-wcomp zsh-wcomp-install)" -type fasd >/dev/null 2>&1 && eval "$(fasd --init auto)" +exist fasd && eval "$(fasd --init auto)" # any alias a='fasd -a' diff --git a/sh/.config/sh/alias.d/yay.sh b/sh/.config/sh/alias.d/yay.sh index 3e18c2e..62f99a6 100644 --- a/sh/.config/sh/alias.d/yay.sh +++ b/sh/.config/sh/alias.d/yay.sh @@ -6,28 +6,28 @@ # Also makes yay call paru since that is the new hotness # (or at least I want to try it) -type paru >/dev/null 2>&1 && { +exist paru && { # recreate the normal look of yay alias yay="paru --bottomup" } syu() { - type topgrade >/dev/null 2>&1 && { + exist topgrade && { topgrade return } - type paru >/dev/null 2>&1 && { + exist paru && { paru return } - type yay >/dev/null 2>&1 && { + exist yay && { yay return } - type pacman >/dev/null 2>&1 && { + exist pacman && { echo "Did not find paru, or yay installed. Updates will not be applied to aur packages." sudo pacman -Syu return From 3cee46358e3417d7891c0ecfcc86af83ece70a11 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sun, 30 Jan 2022 11:38:31 +0100 Subject: [PATCH 7/7] sh: Add serve alias to create a quick file server Quickly put up a file server in the current directory by typing `serve` and the rest is figured out automatically. Makes use of `sfz`, `gossa`, `rossa` in that order to set up the file server. --- sh/.config/sh/alias.d/sfz.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 sh/.config/sh/alias.d/sfz.sh diff --git a/sh/.config/sh/alias.d/sfz.sh b/sh/.config/sh/alias.d/sfz.sh new file mode 100644 index 0000000..6d0daf8 --- /dev/null +++ b/sh/.config/sh/alias.d/sfz.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env sh +## Quickly bring up a file server for +# the current directory. + +if exist sfz; then + alias serve="sfz" +elif exist gossa; then + alias serve="gossa" +elif exist rossa; then + alias serve="rossa" +fi