diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 363350b..4ecde1a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -22,9 +22,9 @@ lint: - shfmt -version script: - echo "--------- CHECKING POSIX SHELLSCRIPTS -------------" - - find . -type f -name '*.sh' | ifne xargs shfmt -d -i 2 + - find . -type f -name '*.sh' -not -path '*/pomo-app/*' | ifne xargs shfmt -d -i 4 - echo "--------- CHECKING ZSH SHELLSCRIPTS -------------" - - find . -type f -name '*.zsh' | ifne xargs shfmt -d -i 2 + - find . -type f -name '*.zsh' -not -path '*/pomo-app/*' | ifne xargs shfmt -d -i 4 test: stage: test diff --git a/bootstrap/install_packages.sh b/bootstrap/install_packages.sh index b6a3d80..4f812fb 100755 --- a/bootstrap/install_packages.sh +++ b/bootstrap/install_packages.sh @@ -10,83 +10,83 @@ packages="${BOOTSTRAP_PACKAGES:-packages.txt}" main() { - local cmd="" - local ret=0 + local cmd="" + local ret=0 - case "$1" in - -v | --version) - printf "Package bootstrap script.\n\n©Marty Oehme\n\nVersion: 0.3\n" - ;; - -h | --help) - printf "Usage: install [-f|--force][-v|--version][-h|--help]\n\n-f Do not ask for any confirmations but force update and installation.\n" - ;; - -f | --force) - install true - ;; - *) - install false - ;; - esac - shift + case "$1" in + -v | --version) + printf "Package bootstrap script.\n\n©Marty Oehme\n\nVersion: 0.3\n" + ;; + -h | --help) + printf "Usage: install [-f|--force][-v|--version][-h|--help]\n\n-f Do not ask for any confirmations but force update and installation.\n" + ;; + -f | --force) + install true + ;; + *) + install false + ;; + esac + shift - $cmd "$@" - ret=$((ret + $?)) - exit $ret + $cmd "$@" + ret=$((ret + $?)) + exit $ret } install_yay() { - # check for existing yay installation - if type yay >/dev/null 2>&1; then - echo "Existing yay installation found ..........................................." - return - fi + # check for existing yay installation + if type yay >/dev/null 2>&1; then + echo "Existing yay installation found ..........................................." + return + fi - # use tmp dir to make yay - target=$(mktemp -d) - git clone https://aur.archlinux.org/yay.git "$target" - cd "$target" || exit - makepkg -si + # use tmp dir to make yay + target=$(mktemp -d) + git clone https://aur.archlinux.org/yay.git "$target" + cd "$target" || exit + makepkg -si } update_repos() { - unattended="$1" - if "$unattended"; then - yay -Sqyy --noconfirm - else - yay -Syy - fi + unattended="$1" + if "$unattended"; then + yay -Sqyy --noconfirm + else + yay -Syy + fi } install_packages() { - unattended="$1" - if "$unattended"; then - yay -Squ --noconfirm --needed - <"$packages" - else - yay -Su --needed - <"$packages" - fi + unattended="$1" + if "$unattended"; then + yay -Squ --noconfirm --needed - <"$packages" + else + yay -Su --needed - <"$packages" + fi } check_consent() { - echo "This will take a while and install many packages. Proceed [y/N]?" - read -r yes - if [[ "$yes" != y* ]]; then - echo "Exiting." - exit - fi + echo "This will take a while and install many packages. Proceed [y/N]?" + read -r yes + if [[ "$yes" != y* ]]; then + echo "Exiting." + exit + fi } install() { - unattended=$1 - echo "Beginning package bootstrap ..............................................." - if ! "$unattended"; then - check_consent - fi - echo "Installing yay ............................................................" - install_yay - echo "Installing apps ..........................................................." - update_repos "$unattended" - install_packages "$unattended" - echo "Done ......................................................................" + unattended=$1 + echo "Beginning package bootstrap ..............................................." + if ! "$unattended"; then + check_consent + fi + echo "Installing yay ............................................................" + install_yay + echo "Installing apps ..........................................................." + update_repos "$unattended" + install_packages "$unattended" + echo "Done ......................................................................" } main "$@" diff --git a/git/.config/sh/alias.d/git.sh b/git/.config/sh/alias.d/git.sh index 7903589..86c93cc 100644 --- a/git/.config/sh/alias.d/git.sh +++ b/git/.config/sh/alias.d/git.sh @@ -1,7 +1,7 @@ #!/usr/bin/env sh if ! exist git; then - return 1 + return 1 fi # git alias @@ -63,13 +63,13 @@ alias gst='git status' # in shells other than zsh, simply fall back to save case "$(ps -cp "$$" -o command="")" in *zsh*) - autoload -Uz is-at-least - if is-at-least 2.13 "$(git --version 2>/dev/null | awk '{print $3}')"; then - alias gsta='git stash push' - else - alias gsta='git stash save' - fi - ;; + autoload -Uz is-at-least + if is-at-least 2.13 "$(git --version 2>/dev/null | awk '{print $3}')"; then + alias gsta='git stash push' + else + alias gsta='git stash save' + fi + ;; *) alias gsta='git stash save' ;; esac alias gstp='git stash pop' diff --git a/install.sh b/install.sh index 095cc63..9b18904 100755 --- a/install.sh +++ b/install.sh @@ -12,81 +12,81 @@ bootstrap_dir="${BOOTSTRAP_DIRECTORY:-./bootstrap}" main() { - local cmd="" - local ret=0 + local cmd="" + local ret=0 - case "$1" in - -v | --version) - printf "Personal system bootstrap script.\n\n©Marty Oehme\n\nVersion: 0.1.1\n" - ;; - -h | --help) - printf "Usage: install [-f|--force][-v|--version][-h|--help]\n\n-f Do not ask for any confirmations but force update and installation.\n" - ;; - -f | --force) - install true - ;; - *) - install false - ;; - esac - shift + case "$1" in + -v | --version) + printf "Personal system bootstrap script.\n\n©Marty Oehme\n\nVersion: 0.1.1\n" + ;; + -h | --help) + printf "Usage: install [-f|--force][-v|--version][-h|--help]\n\n-f Do not ask for any confirmations but force update and installation.\n" + ;; + -f | --force) + install true + ;; + *) + install false + ;; + esac + shift - $cmd "$@" - ret=$((ret + $?)) - exit $ret + $cmd "$@" + ret=$((ret + $?)) + exit $ret } check_consent() { - echo "This will take a while, install many packages and link dotfiles all over the place. Proceed [y/N]?" - read -r yes - if [[ "$yes" != y* ]]; then - echo "Exiting." - exit - fi + echo "This will take a while, install many packages and link dotfiles all over the place. Proceed [y/N]?" + read -r yes + if [[ "$yes" != y* ]]; then + echo "Exiting." + exit + fi } enable_git_hooks() { - if [ "$1" == "false" ]; then - echo "Should we enable git hooks for this repository, so that installed packages are automatically compared when committing? [Y/n]" - read -r no - if [[ "$no" == n* ]]; then - echo "Not changing repository settings." - return + if [ "$1" == "false" ]; then + echo "Should we enable git hooks for this repository, so that installed packages are automatically compared when committing? [Y/n]" + read -r no + if [[ "$no" == n* ]]; then + echo "Not changing repository settings." + return + fi fi - fi - git config --local core.hooksPath .githooks/ - echo "Changed repository settings." + git config --local core.hooksPath .githooks/ + echo "Changed repository settings." } install() { - unattended=$1 - if ! "$unattended"; then - check_consent - fi - echo "====================== BEGINNING INSTALLATION =============================" - if ! "$unattended"; then - export BOOTSTRAP_PACKAGES="bootstrap/packages.txt" - "$bootstrap_dir"/install_packages.sh - else - export BOOTSTRAP_PACKAGES="bootstrap/packages.txt" - "$bootstrap_dir"/install_packages.sh -f - fi - unset BOOTSTRAP_PACKAGES + unattended=$1 + if ! "$unattended"; then + check_consent + fi + echo "====================== BEGINNING INSTALLATION =============================" + if ! "$unattended"; then + export BOOTSTRAP_PACKAGES="bootstrap/packages.txt" + "$bootstrap_dir"/install_packages.sh + else + export BOOTSTRAP_PACKAGES="bootstrap/packages.txt" + "$bootstrap_dir"/install_packages.sh -f + fi + unset BOOTSTRAP_PACKAGES - echo "=================== BEGINNING DOTFILE MANAGEMENT ==========================" - # get all top level directories, remove their slashes and dots - # finally get rid of .dot-directories, since they are for the repo not for my homedir - targets="$(find . -maxdepth 1 -type d | sed -e 's/^\.\/\(.*\)$/\1/' | sed -e '/^\./d')" + echo "=================== BEGINNING DOTFILE MANAGEMENT ==========================" + # get all top level directories, remove their slashes and dots + # finally get rid of .dot-directories, since they are for the repo not for my homedir + targets="$(find . -maxdepth 1 -type d | sed -e 's/^\.\/\(.*\)$/\1/' | sed -e '/^\./d')" - # shellcheck disable=2086 - # -- for some reason stow only works with unqoted var expansion - stow -R ${targets} 2> >(grep -v 'Absolute/relative mismatch between Stow dir' 1>&2) + # shellcheck disable=2086 + # -- for some reason stow only works with unqoted var expansion + stow -R ${targets} 2> >(grep -v 'Absolute/relative mismatch between Stow dir' 1>&2) - echo "================== ENABLING GIT REPOSITORY HOOKS ==========================" - enable_git_hooks "$unattended" + echo "================== ENABLING GIT REPOSITORY HOOKS ==========================" + enable_git_hooks "$unattended" - echo "====================== INSTALLATION FINISHED ==============================" - exit 0 + echo "====================== INSTALLATION FINISHED ==============================" + exit 0 } main "$@" diff --git a/mail/.config/sh/alias.d/fzfmail.sh b/mail/.config/sh/alias.d/fzfmail.sh index 7e55433..6fd7e7f 100644 --- a/mail/.config/sh/alias.d/fzfmail.sh +++ b/mail/.config/sh/alias.d/fzfmail.sh @@ -15,65 +15,65 @@ # re-tag with if exist fzf; then - # Allow fuzzy search filtering of a notmuch search query - fzfmail() { - # shellcheck disable=2016 # we only want the expression to expand when fzf preview is actually called not by the shell - if [ -z "$1" ]; then - # interactive query - fzfmail_mails=$( - printf " + # Allow fuzzy search filtering of a notmuch search query + fzfmail() { + # shellcheck disable=2016 # we only want the expression to expand when fzf preview is actually called not by the shell + if [ -z "$1" ]; then + # interactive query + fzfmail_mails=$( + printf " \nStart a notmuch search query:\n" | - fzf --multi \ - --header "tag: | from: | to: | subject: | folder: | date: || and | not | or | near | adj || read | tag" \ - --bind "change:reload:notmuch search {q} || true" \ - --bind "ctrl-a:toggle-all" \ - --bind '?:toggle-preview' \ - --expect 'ctrl-t,esc' \ - --preview='notmuch show --part=1 $(echo {} | cut -d" " -f1)' \ - --preview-window hidden \ - --phony | - cut -d" " -f1 - ) - else - # pre-queried fuzzy search - fzfmail_mails=$( - notmuch search "$*" | - fzf --multi \ - --header " read | tag" \ - --bind "ctrl-a:toggle-all" \ - --bind '?:toggle-preview' \ - --expect 'ctrl-t,esc' \ - --preview='notmuch show --part=1 $(echo {} | cut -d" " -f1)' \ - --preview-window hidden | - cut -d" " -f1 - ) - fi + fzf --multi \ + --header "tag: | from: | to: | subject: | folder: | date: || and | not | or | near | adj || read | tag" \ + --bind "change:reload:notmuch search {q} || true" \ + --bind "ctrl-a:toggle-all" \ + --bind '?:toggle-preview' \ + --expect 'ctrl-t,esc' \ + --preview='notmuch show --part=1 $(echo {} | cut -d" " -f1)' \ + --preview-window hidden \ + --phony | + cut -d" " -f1 + ) + else + # pre-queried fuzzy search + fzfmail_mails=$( + notmuch search "$*" | + fzf --multi \ + --header " read | tag" \ + --bind "ctrl-a:toggle-all" \ + --bind '?:toggle-preview' \ + --expect 'ctrl-t,esc' \ + --preview='notmuch show --part=1 $(echo {} | cut -d" " -f1)' \ + --preview-window hidden | + cut -d" " -f1 + ) + fi - # find out expected action - fzfmail_action=$(echo "$fzfmail_mails" | head -n1) - # quit on esc pressed -- do not do anything with selected results - if echo "$fzfmail_action" | grep -qe 'esc'; then return 0; fi + # find out expected action + fzfmail_action=$(echo "$fzfmail_mails" | head -n1) + # quit on esc pressed -- do not do anything with selected results + if echo "$fzfmail_action" | grep -qe 'esc'; then return 0; fi - # get the selected mails - fzfmail_mails=$(echo "$fzfmail_mails" | tail -n+2) + # get the selected mails + fzfmail_mails=$(echo "$fzfmail_mails" | tail -n+2) - # tag mails - if echo "$fzfmail_action" | grep -qe 'ctrl-t'; then - printf "current tags: %s\n" "$(notmuch search --output=tags "$fzfmail_mails" | tr '\n' ' ')" - printf "add tags with +tag; remove with -tag\n" - printf "apply tags: " - read -r fzfmail_tags - notmuch tag "$fzfmail_tags" -- "$fzfmail_mails" - return 0 - fi + # tag mails + if echo "$fzfmail_action" | grep -qe 'ctrl-t'; then + printf "current tags: %s\n" "$(notmuch search --output=tags "$fzfmail_mails" | tr '\n' ' ')" + printf "add tags with +tag; remove with -tag\n" + printf "apply tags: " + read -r fzfmail_tags + notmuch tag "$fzfmail_tags" -- "$fzfmail_mails" + return 0 + fi - # display the mails, in semi-readable format - # highlight subject line in color - # allow moving through results with n/p - notmuch show "$fzfmail_mails" | sed -e 's/^\fmessage{.*$/MESSAGE:/' -e '/^\f[a-z]/d' -e 's/^Subject:/\o033[41mSubject:\o033[0m/' | less --pattern '^MESSAGE:$' -R + # display the mails, in semi-readable format + # highlight subject line in color + # allow moving through results with n/p + notmuch show "$fzfmail_mails" | sed -e 's/^\fmessage{.*$/MESSAGE:/' -e '/^\f[a-z]/d' -e 's/^Subject:/\o033[41mSubject:\o033[0m/' | less --pattern '^MESSAGE:$' -R - unset fzfmail_mails - unset fzfmail_action - unset fzfmail_tags - } + unset fzfmail_mails + unset fzfmail_action + unset fzfmail_tags + } fi diff --git a/qutebrowser/.local/share/qutebrowser/userscripts/translate_google.sh b/qutebrowser/.local/share/qutebrowser/userscripts/translate_google.sh index 23de0af..cc22753 100755 --- a/qutebrowser/.local/share/qutebrowser/userscripts/translate_google.sh +++ b/qutebrowser/.local/share/qutebrowser/userscripts/translate_google.sh @@ -5,47 +5,47 @@ # Adapted code from https://github.com/AckslD/Qute-Translate, with much gratitude. while [ $# -gt 0 ]; do - case $1 in - -s | --source) - QUTE_TRANS_SOURCE=$2 - shift - shift - ;; - -t | --target) - QUTE_TRANS_TARGET=$2 - shift - shift - ;; - --url) - QUTE_TRANS_URL="true" - shift - ;; - --text) - QUTE_TRANS_URL="false" - shift - ;; - esac + case $1 in + -s | --source) + QUTE_TRANS_SOURCE=$2 + shift + shift + ;; + -t | --target) + QUTE_TRANS_TARGET=$2 + shift + shift + ;; + --url) + QUTE_TRANS_URL="true" + shift + ;; + --text) + QUTE_TRANS_URL="false" + shift + ;; + esac done if [ -z "$QUTE_TRANS_SOURCE" ]; then - # Default use automatic language for source - QUTE_TRANS_SOURCE="auto" + # Default use automatic language for source + QUTE_TRANS_SOURCE="auto" fi if [ -z "$QUTE_TRANS_TARGET" ]; then - # Default use English for target - QUTE_TRANS_TARGET="en" + # Default use English for target + QUTE_TRANS_TARGET="en" fi if [ "$QUTE_TRANS_URL" = "false" ]; then - # Translate selected text - PAGE="https://translate.google.com/#view=home&op=translate&" - CONT_KEY="text" - CONTENT=$QUTE_SELECTED_TEXT + # Translate selected text + PAGE="https://translate.google.com/#view=home&op=translate&" + CONT_KEY="text" + CONTENT=$QUTE_SELECTED_TEXT else - # Default translate URL - PAGE="https://translate.google.com/translate?" - CONT_KEY="u" - CONTENT=$QUTE_URL + # Default translate URL + PAGE="https://translate.google.com/translate?" + CONT_KEY="u" + CONTENT=$QUTE_URL fi echo "open -t ${PAGE}sl=$QUTE_TRANS_SOURCE&tl=$QUTE_TRANS_TARGET&$CONT_KEY=$CONTENT" >>"$QUTE_FIFO" diff --git a/services/.local/share/services/x-started-confirm.sh b/services/.local/share/services/x-started-confirm.sh index 09cfff4..3dc9489 100755 --- a/services/.local/share/services/x-started-confirm.sh +++ b/services/.local/share/services/x-started-confirm.sh @@ -4,17 +4,17 @@ COUNTER=0 while true; do - # Check whether or not socket exists - if [ -S /tmp/.X11-unix/X0 ]; then - exit 0 - fi + # Check whether or not socket exists + if [ -S /tmp/.X11-unix/X0 ]; then + exit 0 + fi - ((++COUNTER)) + ((++COUNTER)) - if [ "$COUNTER" -gt 20 ]; then - printf "X did not start in time\n" - exit 1 - fi - printf "X not yet started, counter at %s\n" "$COUNTER" - sleep 1 + if [ "$COUNTER" -gt 20 ]; then + printf "X did not start in time\n" + exit 1 + fi + printf "X not yet started, counter at %s\n" "$COUNTER" + sleep 1 done diff --git a/sh/.config/sh/alias.d/enable-fasd-hook.sh b/sh/.config/sh/alias.d/enable-fasd-hook.sh index 67698a1..3d79d04 100644 --- a/sh/.config/sh/alias.d/enable-fasd-hook.sh +++ b/sh/.config/sh/alias.d/enable-fasd-hook.sh @@ -21,11 +21,11 @@ alias zz='fasd_cd -d -i' # or manually load the modules and NOT have fasd_cd # it's easier to use this function fasd_cd() { - fasd_ret="$(fasd -d "$@")" - if [ -d "$fasd_ret" ]; then - cd "$fasd_ret" || exit - else - print "$fasd_ret" - fi - unset fasd_ret + fasd_ret="$(fasd -d "$@")" + if [ -d "$fasd_ret" ]; then + cd "$fasd_ret" || exit + else + print "$fasd_ret" + fi + unset fasd_ret } diff --git a/sh/.config/sh/alias.d/fontlist.sh b/sh/.config/sh/alias.d/fontlist.sh index 10281f5..0d8fab6 100644 --- a/sh/.config/sh/alias.d/fontlist.sh +++ b/sh/.config/sh/alias.d/fontlist.sh @@ -6,5 +6,5 @@ # alias fonts='fc-list -f ''%{family}\n'' | awk ''!x[$0]++''' fontfamilies() { - fc-list -f '%{family}\n' | awk '!x[$0]++' + fc-list -f '%{family}\n' | awk '!x[$0]++' } diff --git a/sh/.config/sh/alias.d/ssh-agent-autoconfiguration.sh b/sh/.config/sh/alias.d/ssh-agent-autoconfiguration.sh index 16e2921..65ce649 100644 --- a/sh/.config/sh/alias.d/ssh-agent-autoconfiguration.sh +++ b/sh/.config/sh/alias.d/ssh-agent-autoconfiguration.sh @@ -31,184 +31,184 @@ declare -a _LIVE_AGENT_SOCK_LIST _LIVE_AGENT_SOCK_LIST=() _debug_print() { - if [[ $_DEBUG -gt 0 ]]; then - printf "%s\n" "$1" - fi + if [[ $_DEBUG -gt 0 ]]; then + printf "%s\n" "$1" + fi } find_all_ssh_agent_sockets() { - _SSH_AGENT_SOCKETS=$(find /tmp/ -type s -name agent.\* 2>/dev/null | grep '/tmp/ssh-.*/agent.*') - _debug_print "$_SSH_AGENT_SOCKETS" + _SSH_AGENT_SOCKETS=$(find /tmp/ -type s -name agent.\* 2>/dev/null | grep '/tmp/ssh-.*/agent.*') + _debug_print "$_SSH_AGENT_SOCKETS" } find_all_gpg_agent_sockets() { - _GPG_AGENT_SOCKETS=$(find /tmp/ -type s -name S.gpg-agent.ssh 2>/dev/null | grep '/tmp/gpg-.*/S.gpg-agent.ssh') - _debug_print "$_GPG_AGENT_SOCKETS" + _GPG_AGENT_SOCKETS=$(find /tmp/ -type s -name S.gpg-agent.ssh 2>/dev/null | grep '/tmp/gpg-.*/S.gpg-agent.ssh') + _debug_print "$_GPG_AGENT_SOCKETS" } find_all_gnome_keyring_agent_sockets() { - _GNOME_KEYRING_AGENT_SOCKETS=$(find /tmp/ -type s -name "ssh" 2>/dev/null | grep '/tmp/keyring-.*/ssh$') - _debug_print "$_GNOME_KEYRING_AGENT_SOCKETS" + _GNOME_KEYRING_AGENT_SOCKETS=$(find /tmp/ -type s -name "ssh" 2>/dev/null | grep '/tmp/keyring-.*/ssh$') + _debug_print "$_GNOME_KEYRING_AGENT_SOCKETS" } find_all_osx_keychain_agent_sockets() { - [[ -n "$TMPDIR" ]] || TMPDIR=/tmp - _OSX_KEYCHAIN_AGENT_SOCKETS=$(find $TMPDIR/ -type s -regex '.*/ssh-.*/agent..*$' 2>/dev/null) - _debug_print "$_OSX_KEYCHAIN_AGENT_SOCKETS" + [[ -n "$TMPDIR" ]] || TMPDIR=/tmp + _OSX_KEYCHAIN_AGENT_SOCKETS=$(find $TMPDIR/ -type s -regex '.*/ssh-.*/agent..*$' 2>/dev/null) + _debug_print "$_OSX_KEYCHAIN_AGENT_SOCKETS" } test_agent_socket() { - local SOCKET=$1 - SSH_AUTH_SOCK=$SOCKET ssh-add -l 2>/dev/null >/dev/null - result=$? + local SOCKET=$1 + SSH_AUTH_SOCK=$SOCKET ssh-add -l 2>/dev/null >/dev/null + result=$? - _debug_print $result + _debug_print $result - if [[ $result -eq 0 ]]; then - # contactible and has keys loaded - _KEY_COUNT=$(SSH_AUTH_SOCK=$SOCKET ssh-add -l | wc -l | tr -d ' ') - fi - - if [[ $result -eq 1 ]]; then - # contactible butno keys loaded - _KEY_COUNT=0 - fi - - if [ $result -eq 0 ] || [ $result -eq 1 ]; then - if [[ -n "$_LIVE_AGENT_LIST" ]]; then - _LIVE_AGENT_LIST="${_LIVE_AGENT_LIST} ${SOCKET}:$_KEY_COUNT" - else - _LIVE_AGENT_LIST="${SOCKET}:$_KEY_COUNT" + if [[ $result -eq 0 ]]; then + # contactible and has keys loaded + _KEY_COUNT=$(SSH_AUTH_SOCK=$SOCKET ssh-add -l | wc -l | tr -d ' ') fi - return 0 - fi - return 1 + if [[ $result -eq 1 ]]; then + # contactible butno keys loaded + _KEY_COUNT=0 + fi + + if [ $result -eq 0 ] || [ $result -eq 1 ]; then + if [[ -n "$_LIVE_AGENT_LIST" ]]; then + _LIVE_AGENT_LIST="${_LIVE_AGENT_LIST} ${SOCKET}:$_KEY_COUNT" + else + _LIVE_AGENT_LIST="${SOCKET}:$_KEY_COUNT" + fi + return 0 + fi + + return 1 } find_live_gnome_keyring_agents() { - for i in $_GNOME_KEYRING_AGENT_SOCKETS; do - test_agent_socket "$i" - done + for i in $_GNOME_KEYRING_AGENT_SOCKETS; do + test_agent_socket "$i" + done } find_live_osx_keychain_agents() { - for i in $_OSX_KEYCHAIN_AGENT_SOCKETS; do - test_agent_socket "$i" - done + for i in $_OSX_KEYCHAIN_AGENT_SOCKETS; do + test_agent_socket "$i" + done } find_live_gpg_agents() { - for i in $_GPG_AGENT_SOCKETS; do - test_agent_socket "$i" - done + for i in $_GPG_AGENT_SOCKETS; do + test_agent_socket "$i" + done } find_live_ssh_agents() { - for i in $_SSH_AGENT_SOCKETS; do - test_agent_socket "$i" - done + for i in $_SSH_AGENT_SOCKETS; do + test_agent_socket "$i" + done } function fingerprints() { - local file="$1" - while read -r l; do - [[ -n $l && ${l###} == "$l" ]] && ssh-keygen -l -f /dev/stdin <<<"$l" - done <"$file" + local file="$1" + while read -r l; do + [[ -n $l && ${l###} == "$l" ]] && ssh-keygen -l -f /dev/stdin <<<"$l" + done <"$file" } find_all_agent_sockets() { - _SHOW_IDENTITY=0 - if [ "$1" = "-i" ]; then - _SHOW_IDENTITY=1 - fi - _LIVE_AGENT_LIST= - find_all_ssh_agent_sockets - find_all_gpg_agent_sockets - find_all_gnome_keyring_agent_sockets - find_all_osx_keychain_agent_sockets - find_live_ssh_agents - find_live_gpg_agents - find_live_gnome_keyring_agents - find_live_osx_keychain_agents - _debug_print "$_LIVE_AGENT_LIST" - _LIVE_AGENT_LIST=$(echo "$_LIVE_AGENT_LIST" | tr ' ' '\n' | sort -n -t: -k 2 -k 1 | uniq) - _LIVE_AGENT_SOCK_LIST=() - _debug_print "SORTED: $_LIVE_AGENT_LIST" - if [[ $_SHOW_IDENTITY -gt 0 ]]; then - i=0 - for a in $_LIVE_AGENT_LIST; do - sock=${a/:*/} - _LIVE_AGENT_SOCK_LIST[$i]=$sock - # technically we could have multiple keys forwarded - # But I haven't seen anyone do it - akeys=$(SSH_AUTH_SOCK=$sock ssh-add -l) - fingerprint=$(echo "${akeys}" | awk '{print $2}') - if [ -e ~/.ssh/authorized_keys ]; then - authorized_entry=$(fingerprints ~/.ssh/authorized_keys | grep "$fingerprint") - fi - comment=$(echo "${authorized_entry}" | awk '{print $3,$4,$5,$6,$7}') - printf "export SSH_AUTH_SOCK=%s \t#%i) \t%s\n" "$sock" $((i + 1)) "$comment" - i=$((i + 1)) - done - else - printf "%s\n" "$_LIVE_AGENT_LIST" | sed -e 's/ /\n/g' | sort -n -t: -k 2 -k 1 - fi + _SHOW_IDENTITY=0 + if [ "$1" = "-i" ]; then + _SHOW_IDENTITY=1 + fi + _LIVE_AGENT_LIST= + find_all_ssh_agent_sockets + find_all_gpg_agent_sockets + find_all_gnome_keyring_agent_sockets + find_all_osx_keychain_agent_sockets + find_live_ssh_agents + find_live_gpg_agents + find_live_gnome_keyring_agents + find_live_osx_keychain_agents + _debug_print "$_LIVE_AGENT_LIST" + _LIVE_AGENT_LIST=$(echo "$_LIVE_AGENT_LIST" | tr ' ' '\n' | sort -n -t: -k 2 -k 1 | uniq) + _LIVE_AGENT_SOCK_LIST=() + _debug_print "SORTED: $_LIVE_AGENT_LIST" + if [[ $_SHOW_IDENTITY -gt 0 ]]; then + i=0 + for a in $_LIVE_AGENT_LIST; do + sock=${a/:*/} + _LIVE_AGENT_SOCK_LIST[$i]=$sock + # technically we could have multiple keys forwarded + # But I haven't seen anyone do it + akeys=$(SSH_AUTH_SOCK=$sock ssh-add -l) + fingerprint=$(echo "${akeys}" | awk '{print $2}') + if [ -e ~/.ssh/authorized_keys ]; then + authorized_entry=$(fingerprints ~/.ssh/authorized_keys | grep "$fingerprint") + fi + comment=$(echo "${authorized_entry}" | awk '{print $3,$4,$5,$6,$7}') + printf "export SSH_AUTH_SOCK=%s \t#%i) \t%s\n" "$sock" $((i + 1)) "$comment" + i=$((i + 1)) + done + else + printf "%s\n" "$_LIVE_AGENT_LIST" | sed -e 's/ /\n/g' | sort -n -t: -k 2 -k 1 + fi } set_ssh_agent_socket() { - if [ "$1" = "-c" ] || [ "$1" = "--choose" ]; then - find_all_agent_sockets -i + if [ "$1" = "-c" ] || [ "$1" = "--choose" ]; then + find_all_agent_sockets -i - if [ -z "$_LIVE_AGENT_LIST" ]; then - echo "No agents found" - return 1 + if [ -z "$_LIVE_AGENT_LIST" ]; then + echo "No agents found" + return 1 + fi + + echo -n "Choose (1-${#_LIVE_AGENT_SOCK_LIST[@]})? " + read -r choice + if [ -n "$choice" ]; then + n=$((choice - 1)) + if [ -z "${_LIVE_AGENT_SOCK_LIST[$n]}" ]; then + echo "Invalid choice" + return 1 + fi + echo "Setting export SSH_AUTH_SOCK=${_LIVE_AGENT_SOCK_LIST[$n]}" + export SSH_AUTH_SOCK=${_LIVE_AGENT_SOCK_LIST[$n]} + fi + else + # Choose the first available + SOCK=$(find_all_agent_sockets | tail -n 1 | awk -F: '{print $1}') + if [ -z "$SOCK" ]; then + return 1 + fi + export SSH_AUTH_SOCK=$SOCK fi - echo -n "Choose (1-${#_LIVE_AGENT_SOCK_LIST[@]})? " - read -r choice - if [ -n "$choice" ]; then - n=$((choice - 1)) - if [ -z "${_LIVE_AGENT_SOCK_LIST[$n]}" ]; then - echo "Invalid choice" - return 1 - fi - echo "Setting export SSH_AUTH_SOCK=${_LIVE_AGENT_SOCK_LIST[$n]}" - export SSH_AUTH_SOCK=${_LIVE_AGENT_SOCK_LIST[$n]} + # set agent pid + if [ -n "$SSH_AUTH_SOCK" ]; then + export SSH_AGENT_PID=$(($(echo "$SSH_AUTH_SOCK" | cut -d. -f2) + 1)) fi - else - # Choose the first available - SOCK=$(find_all_agent_sockets | tail -n 1 | awk -F: '{print $1}') - if [ -z "$SOCK" ]; then - return 1 - fi - export SSH_AUTH_SOCK=$SOCK - fi - # set agent pid - if [ -n "$SSH_AUTH_SOCK" ]; then - export SSH_AGENT_PID=$(($(echo "$SSH_AUTH_SOCK" | cut -d. -f2) + 1)) - fi - - return 0 + return 0 } ssh-find-agent() { - if [ "$1" = "-c" ] || [ "$1" = "--choose" ]; then - set_ssh_agent_socket -c - return $? - elif [ "$1" = "-a" ] || [ "$1" = "--auto" ]; then - set_ssh_agent_socket - return $? - else - find_all_agent_sockets -i - return 0 - fi + if [ "$1" = "-c" ] || [ "$1" = "--choose" ]; then + set_ssh_agent_socket -c + return $? + elif [ "$1" = "-a" ] || [ "$1" = "--auto" ]; then + set_ssh_agent_socket + return $? + else + find_all_agent_sockets -i + return 0 + fi } # Automatically add ssh-agent to any new ssh connection ssh-find-agent -a if [ -z "$SSH_AUTH_SOCK" ]; then - eval "$(ssh-agent)" >/dev/null - ssh-add -l >/dev/null || alias ssh='ssh-add -l >/dev/null || ssh-add && unalias ssh; ssh' + eval "$(ssh-agent)" >/dev/null + ssh-add -l >/dev/null || alias ssh='ssh-add -l >/dev/null || ssh-add && unalias ssh; ssh' fi diff --git a/sh/.config/sh/alias.d/yay.sh b/sh/.config/sh/alias.d/yay.sh index afc7389..3e18c2e 100644 --- a/sh/.config/sh/alias.d/yay.sh +++ b/sh/.config/sh/alias.d/yay.sh @@ -7,29 +7,29 @@ # (or at least I want to try it) type paru >/dev/null 2>&1 && { - # recreate the normal look of yay - alias yay="paru --bottomup" + # recreate the normal look of yay + alias yay="paru --bottomup" } syu() { - type topgrade >/dev/null 2>&1 && { - topgrade - return - } + type topgrade >/dev/null 2>&1 && { + topgrade + return + } - type paru >/dev/null 2>&1 && { - paru - return - } + type paru >/dev/null 2>&1 && { + paru + return + } - type yay >/dev/null 2>&1 && { - yay - return - } + type yay >/dev/null 2>&1 && { + yay + return + } - type pacman >/dev/null 2>&1 && { - echo "Did not find paru, or yay installed. Updates will not be applied to aur packages." - sudo pacman -Syu - return - } + type pacman >/dev/null 2>&1 && { + echo "Did not find paru, or yay installed. Updates will not be applied to aur packages." + sudo pacman -Syu + return + } } diff --git a/sh/.config/sh/profile.d/autostartx.sh b/sh/.config/sh/profile.d/autostartx.sh index 08bce98..4521f05 100644 --- a/sh/.config/sh/profile.d/autostartx.sh +++ b/sh/.config/sh/profile.d/autostartx.sh @@ -1,5 +1,5 @@ #!/usr/bin/env sh if [ ! "$DISPLAY" ] && [ -n "$XDG_VTNR" ] && [ "$XDG_VTNR" -eq 1 ]; then - exec startx "$XDG_CONFIG_HOME"/xresources/xinitrc + exec startx "$XDG_CONFIG_HOME"/xresources/xinitrc fi diff --git a/tmux/.config/sh/alias.d/tmux.sh b/tmux/.config/sh/alias.d/tmux.sh index a73b6a7..12459be 100644 --- a/tmux/.config/sh/alias.d/tmux.sh +++ b/tmux/.config/sh/alias.d/tmux.sh @@ -8,49 +8,49 @@ alias tmux="tmux -f ${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf" # fzf if exist fzf; then - # fzf select a tmux session to connect to, with pane preview - alias tm='_fzf_tmux_attach_start_session' - alias tl=tm + # fzf select a tmux session to connect to, with pane preview + alias tm='_fzf_tmux_attach_start_session' + alias tl=tm else - alias tm='tmux_attach_start' - # show a list of running tmux sessions - alias tl='tmux list-sessions -F "#{session_name}" 2>/dev/null ' + alias tm='tmux_attach_start' + # show a list of running tmux sessions + alias tl='tmux list-sessions -F "#{session_name}" 2>/dev/null ' fi _fzf_tmux_list_sessions() { - tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf \ - --layout=reverse \ - --height=50% \ - --border \ - --prompt="Session> " \ - --preview="tmux_pane_tree {}" \ - --preview-window=right:80% \ - --print-query + tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf \ + --layout=reverse \ + --height=50% \ + --border \ + --prompt="Session> " \ + --preview="tmux_pane_tree {}" \ + --preview-window=right:80% \ + --print-query } _fzf_tmux_attach_start_session() { - if [ -z "$1" ]; then - result=$(_fzf_tmux_list_sessions) - case "$?" in - 0) - # found a session, attaching - tmux_attach_start "$(echo "$result" | tail --lines=1)" - ;; - 1) - # did not find a session, creating - result=$(echo "$result" | head --lines=1) - # if . was only thing entered, create one for current dir - if [ "$result" = "." ]; then - tmux_attach_start - # create for query name - else - tmux_attach_start "$result" - fi - ;; - esac - else - tmux_attach_start "$1" - fi + if [ -z "$1" ]; then + result=$(_fzf_tmux_list_sessions) + case "$?" in + 0) + # found a session, attaching + tmux_attach_start "$(echo "$result" | tail --lines=1)" + ;; + 1) + # did not find a session, creating + result=$(echo "$result" | head --lines=1) + # if . was only thing entered, create one for current dir + if [ "$result" = "." ]; then + tmux_attach_start + # create for query name + else + tmux_attach_start "$result" + fi + ;; + esac + else + tmux_attach_start "$1" + fi } unset choice