repo: Update linting for 4-spaced shell scripts

This commit is contained in:
Marty Oehme 2021-04-04 20:52:52 +02:00
parent 864ec3d03b
commit f4400da743
Signed by: Marty
GPG Key ID: B7538B8F50A1C800
13 changed files with 417 additions and 417 deletions

View File

@ -22,9 +22,9 @@ lint:
- shfmt -version - shfmt -version
script: script:
- echo "--------- CHECKING POSIX SHELLSCRIPTS -------------" - 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 -------------" - 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: test:
stage: test stage: test

View File

@ -10,83 +10,83 @@
packages="${BOOTSTRAP_PACKAGES:-packages.txt}" packages="${BOOTSTRAP_PACKAGES:-packages.txt}"
main() { main() {
local cmd="" local cmd=""
local ret=0 local ret=0
case "$1" in case "$1" in
-v | --version) -v | --version)
printf "Package bootstrap script.\n\n©Marty Oehme\n\nVersion: 0.3\n" printf "Package bootstrap script.\n\n©Marty Oehme\n\nVersion: 0.3\n"
;; ;;
-h | --help) -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" 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) -f | --force)
install true install true
;; ;;
*) *)
install false install false
;; ;;
esac esac
shift shift
$cmd "$@" $cmd "$@"
ret=$((ret + $?)) ret=$((ret + $?))
exit $ret exit $ret
} }
install_yay() { install_yay() {
# check for existing yay installation # check for existing yay installation
if type yay >/dev/null 2>&1; then if type yay >/dev/null 2>&1; then
echo "Existing yay installation found ..........................................." echo "Existing yay installation found ..........................................."
return return
fi fi
# use tmp dir to make yay # use tmp dir to make yay
target=$(mktemp -d) target=$(mktemp -d)
git clone https://aur.archlinux.org/yay.git "$target" git clone https://aur.archlinux.org/yay.git "$target"
cd "$target" || exit cd "$target" || exit
makepkg -si makepkg -si
} }
update_repos() { update_repos() {
unattended="$1" unattended="$1"
if "$unattended"; then if "$unattended"; then
yay -Sqyy --noconfirm yay -Sqyy --noconfirm
else else
yay -Syy yay -Syy
fi fi
} }
install_packages() { install_packages() {
unattended="$1" unattended="$1"
if "$unattended"; then if "$unattended"; then
yay -Squ --noconfirm --needed - <"$packages" yay -Squ --noconfirm --needed - <"$packages"
else else
yay -Su --needed - <"$packages" yay -Su --needed - <"$packages"
fi fi
} }
check_consent() { check_consent() {
echo "This will take a while and install many packages. Proceed [y/N]?" echo "This will take a while and install many packages. Proceed [y/N]?"
read -r yes read -r yes
if [[ "$yes" != y* ]]; then if [[ "$yes" != y* ]]; then
echo "Exiting." echo "Exiting."
exit exit
fi fi
} }
install() { install() {
unattended=$1 unattended=$1
echo "Beginning package bootstrap ..............................................." echo "Beginning package bootstrap ..............................................."
if ! "$unattended"; then if ! "$unattended"; then
check_consent check_consent
fi fi
echo "Installing yay ............................................................" echo "Installing yay ............................................................"
install_yay install_yay
echo "Installing apps ..........................................................." echo "Installing apps ..........................................................."
update_repos "$unattended" update_repos "$unattended"
install_packages "$unattended" install_packages "$unattended"
echo "Done ......................................................................" echo "Done ......................................................................"
} }
main "$@" main "$@"

View File

@ -1,7 +1,7 @@
#!/usr/bin/env sh #!/usr/bin/env sh
if ! exist git; then if ! exist git; then
return 1 return 1
fi fi
# git alias # git alias
@ -63,13 +63,13 @@ alias gst='git status'
# in shells other than zsh, simply fall back to save # in shells other than zsh, simply fall back to save
case "$(ps -cp "$$" -o command="")" in case "$(ps -cp "$$" -o command="")" in
*zsh*) *zsh*)
autoload -Uz is-at-least autoload -Uz is-at-least
if is-at-least 2.13 "$(git --version 2>/dev/null | awk '{print $3}')"; then if is-at-least 2.13 "$(git --version 2>/dev/null | awk '{print $3}')"; then
alias gsta='git stash push' alias gsta='git stash push'
else else
alias gsta='git stash save' alias gsta='git stash save'
fi fi
;; ;;
*) alias gsta='git stash save' ;; *) alias gsta='git stash save' ;;
esac esac
alias gstp='git stash pop' alias gstp='git stash pop'

View File

@ -12,81 +12,81 @@
bootstrap_dir="${BOOTSTRAP_DIRECTORY:-./bootstrap}" bootstrap_dir="${BOOTSTRAP_DIRECTORY:-./bootstrap}"
main() { main() {
local cmd="" local cmd=""
local ret=0 local ret=0
case "$1" in case "$1" in
-v | --version) -v | --version)
printf "Personal system bootstrap script.\n\n©Marty Oehme\n\nVersion: 0.1.1\n" printf "Personal system bootstrap script.\n\n©Marty Oehme\n\nVersion: 0.1.1\n"
;; ;;
-h | --help) -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" 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) -f | --force)
install true install true
;; ;;
*) *)
install false install false
;; ;;
esac esac
shift shift
$cmd "$@" $cmd "$@"
ret=$((ret + $?)) ret=$((ret + $?))
exit $ret exit $ret
} }
check_consent() { check_consent() {
echo "This will take a while, install many packages and link dotfiles all over the place. Proceed [y/N]?" echo "This will take a while, install many packages and link dotfiles all over the place. Proceed [y/N]?"
read -r yes read -r yes
if [[ "$yes" != y* ]]; then if [[ "$yes" != y* ]]; then
echo "Exiting." echo "Exiting."
exit exit
fi fi
} }
enable_git_hooks() { enable_git_hooks() {
if [ "$1" == "false" ]; then if [ "$1" == "false" ]; then
echo "Should we enable git hooks for this repository, so that installed packages are automatically compared when committing? [Y/n]" echo "Should we enable git hooks for this repository, so that installed packages are automatically compared when committing? [Y/n]"
read -r no read -r no
if [[ "$no" == n* ]]; then if [[ "$no" == n* ]]; then
echo "Not changing repository settings." echo "Not changing repository settings."
return return
fi
fi fi
fi git config --local core.hooksPath .githooks/
git config --local core.hooksPath .githooks/ echo "Changed repository settings."
echo "Changed repository settings."
} }
install() { install() {
unattended=$1 unattended=$1
if ! "$unattended"; then if ! "$unattended"; then
check_consent check_consent
fi fi
echo "====================== BEGINNING INSTALLATION =============================" echo "====================== BEGINNING INSTALLATION ============================="
if ! "$unattended"; then if ! "$unattended"; then
export BOOTSTRAP_PACKAGES="bootstrap/packages.txt" export BOOTSTRAP_PACKAGES="bootstrap/packages.txt"
"$bootstrap_dir"/install_packages.sh "$bootstrap_dir"/install_packages.sh
else else
export BOOTSTRAP_PACKAGES="bootstrap/packages.txt" export BOOTSTRAP_PACKAGES="bootstrap/packages.txt"
"$bootstrap_dir"/install_packages.sh -f "$bootstrap_dir"/install_packages.sh -f
fi fi
unset BOOTSTRAP_PACKAGES unset BOOTSTRAP_PACKAGES
echo "=================== BEGINNING DOTFILE MANAGEMENT ==========================" echo "=================== BEGINNING DOTFILE MANAGEMENT =========================="
# get all top level directories, remove their slashes and dots # 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 # 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')" targets="$(find . -maxdepth 1 -type d | sed -e 's/^\.\/\(.*\)$/\1/' | sed -e '/^\./d')"
# shellcheck disable=2086 # shellcheck disable=2086
# -- for some reason stow only works with unqoted var expansion # -- for some reason stow only works with unqoted var expansion
stow -R ${targets} 2> >(grep -v 'Absolute/relative mismatch between Stow dir' 1>&2) stow -R ${targets} 2> >(grep -v 'Absolute/relative mismatch between Stow dir' 1>&2)
echo "================== ENABLING GIT REPOSITORY HOOKS ==========================" echo "================== ENABLING GIT REPOSITORY HOOKS =========================="
enable_git_hooks "$unattended" enable_git_hooks "$unattended"
echo "====================== INSTALLATION FINISHED ==============================" echo "====================== INSTALLATION FINISHED =============================="
exit 0 exit 0
} }
main "$@" main "$@"

View File

@ -15,65 +15,65 @@
# re-tag with <ctrl-t> # re-tag with <ctrl-t>
if exist fzf; then if exist fzf; then
# Allow fuzzy search filtering of a notmuch search query # Allow fuzzy search filtering of a notmuch search query
fzfmail() { fzfmail() {
# shellcheck disable=2016 # we only want the expression to expand when fzf preview is actually called not by the shell # shellcheck disable=2016 # we only want the expression to expand when fzf preview is actually called not by the shell
if [ -z "$1" ]; then if [ -z "$1" ]; then
# interactive query # interactive query
fzfmail_mails=$( fzfmail_mails=$(
printf " printf "
\nStart a notmuch search query:\n" | \nStart a notmuch search query:\n" |
fzf --multi \ fzf --multi \
--header "tag: | from: | to: | subject: | folder: | date: || and | not | or | near | adj || <enter> read | <ctrl-t> tag" \ --header "tag: | from: | to: | subject: | folder: | date: || and | not | or | near | adj || <enter> read | <ctrl-t> tag" \
--bind "change:reload:notmuch search {q} || true" \ --bind "change:reload:notmuch search {q} || true" \
--bind "ctrl-a:toggle-all" \ --bind "ctrl-a:toggle-all" \
--bind '?:toggle-preview' \ --bind '?:toggle-preview' \
--expect 'ctrl-t,esc' \ --expect 'ctrl-t,esc' \
--preview='notmuch show --part=1 $(echo {} | cut -d" " -f1)' \ --preview='notmuch show --part=1 $(echo {} | cut -d" " -f1)' \
--preview-window hidden \ --preview-window hidden \
--phony | --phony |
cut -d" " -f1 cut -d" " -f1
) )
else else
# pre-queried fuzzy search # pre-queried fuzzy search
fzfmail_mails=$( fzfmail_mails=$(
notmuch search "$*" | notmuch search "$*" |
fzf --multi \ fzf --multi \
--header "<enter> read | <ctrl-t> tag" \ --header "<enter> read | <ctrl-t> tag" \
--bind "ctrl-a:toggle-all" \ --bind "ctrl-a:toggle-all" \
--bind '?:toggle-preview' \ --bind '?:toggle-preview' \
--expect 'ctrl-t,esc' \ --expect 'ctrl-t,esc' \
--preview='notmuch show --part=1 $(echo {} | cut -d" " -f1)' \ --preview='notmuch show --part=1 $(echo {} | cut -d" " -f1)' \
--preview-window hidden | --preview-window hidden |
cut -d" " -f1 cut -d" " -f1
) )
fi fi
# find out expected action # find out expected action
fzfmail_action=$(echo "$fzfmail_mails" | head -n1) fzfmail_action=$(echo "$fzfmail_mails" | head -n1)
# quit on esc pressed -- do not do anything with selected results # quit on esc pressed -- do not do anything with selected results
if echo "$fzfmail_action" | grep -qe 'esc'; then return 0; fi if echo "$fzfmail_action" | grep -qe 'esc'; then return 0; fi
# get the selected mails # get the selected mails
fzfmail_mails=$(echo "$fzfmail_mails" | tail -n+2) fzfmail_mails=$(echo "$fzfmail_mails" | tail -n+2)
# tag mails # tag mails
if echo "$fzfmail_action" | grep -qe 'ctrl-t'; then if echo "$fzfmail_action" | grep -qe 'ctrl-t'; then
printf "current tags: %s\n" "$(notmuch search --output=tags "$fzfmail_mails" | tr '\n' ' ')" printf "current tags: %s\n" "$(notmuch search --output=tags "$fzfmail_mails" | tr '\n' ' ')"
printf "add tags with +tag; remove with -tag\n" printf "add tags with +tag; remove with -tag\n"
printf "apply tags: " printf "apply tags: "
read -r fzfmail_tags read -r fzfmail_tags
notmuch tag "$fzfmail_tags" -- "$fzfmail_mails" notmuch tag "$fzfmail_tags" -- "$fzfmail_mails"
return 0 return 0
fi fi
# display the mails, in semi-readable format # display the mails, in semi-readable format
# highlight subject line in color # highlight subject line in color
# allow moving through results with n/p # 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 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_mails
unset fzfmail_action unset fzfmail_action
unset fzfmail_tags unset fzfmail_tags
} }
fi fi

View File

@ -5,47 +5,47 @@
# Adapted code from https://github.com/AckslD/Qute-Translate, with much gratitude. # Adapted code from https://github.com/AckslD/Qute-Translate, with much gratitude.
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case $1 in case $1 in
-s | --source) -s | --source)
QUTE_TRANS_SOURCE=$2 QUTE_TRANS_SOURCE=$2
shift shift
shift shift
;; ;;
-t | --target) -t | --target)
QUTE_TRANS_TARGET=$2 QUTE_TRANS_TARGET=$2
shift shift
shift shift
;; ;;
--url) --url)
QUTE_TRANS_URL="true" QUTE_TRANS_URL="true"
shift shift
;; ;;
--text) --text)
QUTE_TRANS_URL="false" QUTE_TRANS_URL="false"
shift shift
;; ;;
esac esac
done done
if [ -z "$QUTE_TRANS_SOURCE" ]; then if [ -z "$QUTE_TRANS_SOURCE" ]; then
# Default use automatic language for source # Default use automatic language for source
QUTE_TRANS_SOURCE="auto" QUTE_TRANS_SOURCE="auto"
fi fi
if [ -z "$QUTE_TRANS_TARGET" ]; then if [ -z "$QUTE_TRANS_TARGET" ]; then
# Default use English for target # Default use English for target
QUTE_TRANS_TARGET="en" QUTE_TRANS_TARGET="en"
fi fi
if [ "$QUTE_TRANS_URL" = "false" ]; then if [ "$QUTE_TRANS_URL" = "false" ]; then
# Translate selected text # Translate selected text
PAGE="https://translate.google.com/#view=home&op=translate&" PAGE="https://translate.google.com/#view=home&op=translate&"
CONT_KEY="text" CONT_KEY="text"
CONTENT=$QUTE_SELECTED_TEXT CONTENT=$QUTE_SELECTED_TEXT
else else
# Default translate URL # Default translate URL
PAGE="https://translate.google.com/translate?" PAGE="https://translate.google.com/translate?"
CONT_KEY="u" CONT_KEY="u"
CONTENT=$QUTE_URL CONTENT=$QUTE_URL
fi fi
echo "open -t ${PAGE}sl=$QUTE_TRANS_SOURCE&tl=$QUTE_TRANS_TARGET&$CONT_KEY=$CONTENT" >>"$QUTE_FIFO" echo "open -t ${PAGE}sl=$QUTE_TRANS_SOURCE&tl=$QUTE_TRANS_TARGET&$CONT_KEY=$CONTENT" >>"$QUTE_FIFO"

View File

@ -4,17 +4,17 @@
COUNTER=0 COUNTER=0
while true; do while true; do
# Check whether or not socket exists # Check whether or not socket exists
if [ -S /tmp/.X11-unix/X0 ]; then if [ -S /tmp/.X11-unix/X0 ]; then
exit 0 exit 0
fi fi
((++COUNTER)) ((++COUNTER))
if [ "$COUNTER" -gt 20 ]; then if [ "$COUNTER" -gt 20 ]; then
printf "X did not start in time\n" printf "X did not start in time\n"
exit 1 exit 1
fi fi
printf "X not yet started, counter at %s\n" "$COUNTER" printf "X not yet started, counter at %s\n" "$COUNTER"
sleep 1 sleep 1
done done

View File

@ -21,11 +21,11 @@ alias zz='fasd_cd -d -i'
# or manually load the modules and NOT have fasd_cd # or manually load the modules and NOT have fasd_cd
# it's easier to use this function # it's easier to use this function
fasd_cd() { fasd_cd() {
fasd_ret="$(fasd -d "$@")" fasd_ret="$(fasd -d "$@")"
if [ -d "$fasd_ret" ]; then if [ -d "$fasd_ret" ]; then
cd "$fasd_ret" || exit cd "$fasd_ret" || exit
else else
print "$fasd_ret" print "$fasd_ret"
fi fi
unset fasd_ret unset fasd_ret
} }

View File

@ -6,5 +6,5 @@
# alias fonts='fc-list -f ''%{family}\n'' | awk ''!x[$0]++''' # alias fonts='fc-list -f ''%{family}\n'' | awk ''!x[$0]++'''
fontfamilies() { fontfamilies() {
fc-list -f '%{family}\n' | awk '!x[$0]++' fc-list -f '%{family}\n' | awk '!x[$0]++'
} }

View File

@ -31,184 +31,184 @@ declare -a _LIVE_AGENT_SOCK_LIST
_LIVE_AGENT_SOCK_LIST=() _LIVE_AGENT_SOCK_LIST=()
_debug_print() { _debug_print() {
if [[ $_DEBUG -gt 0 ]]; then if [[ $_DEBUG -gt 0 ]]; then
printf "%s\n" "$1" printf "%s\n" "$1"
fi fi
} }
find_all_ssh_agent_sockets() { find_all_ssh_agent_sockets() {
_SSH_AGENT_SOCKETS=$(find /tmp/ -type s -name agent.\* 2>/dev/null | grep '/tmp/ssh-.*/agent.*') _SSH_AGENT_SOCKETS=$(find /tmp/ -type s -name agent.\* 2>/dev/null | grep '/tmp/ssh-.*/agent.*')
_debug_print "$_SSH_AGENT_SOCKETS" _debug_print "$_SSH_AGENT_SOCKETS"
} }
find_all_gpg_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') _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" _debug_print "$_GPG_AGENT_SOCKETS"
} }
find_all_gnome_keyring_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$') _GNOME_KEYRING_AGENT_SOCKETS=$(find /tmp/ -type s -name "ssh" 2>/dev/null | grep '/tmp/keyring-.*/ssh$')
_debug_print "$_GNOME_KEYRING_AGENT_SOCKETS" _debug_print "$_GNOME_KEYRING_AGENT_SOCKETS"
} }
find_all_osx_keychain_agent_sockets() { find_all_osx_keychain_agent_sockets() {
[[ -n "$TMPDIR" ]] || TMPDIR=/tmp [[ -n "$TMPDIR" ]] || TMPDIR=/tmp
_OSX_KEYCHAIN_AGENT_SOCKETS=$(find $TMPDIR/ -type s -regex '.*/ssh-.*/agent..*$' 2>/dev/null) _OSX_KEYCHAIN_AGENT_SOCKETS=$(find $TMPDIR/ -type s -regex '.*/ssh-.*/agent..*$' 2>/dev/null)
_debug_print "$_OSX_KEYCHAIN_AGENT_SOCKETS" _debug_print "$_OSX_KEYCHAIN_AGENT_SOCKETS"
} }
test_agent_socket() { test_agent_socket() {
local SOCKET=$1 local SOCKET=$1
SSH_AUTH_SOCK=$SOCKET ssh-add -l 2>/dev/null >/dev/null SSH_AUTH_SOCK=$SOCKET ssh-add -l 2>/dev/null >/dev/null
result=$? result=$?
_debug_print $result _debug_print $result
if [[ $result -eq 0 ]]; then if [[ $result -eq 0 ]]; then
# contactible and has keys loaded # contactible and has keys loaded
_KEY_COUNT=$(SSH_AUTH_SOCK=$SOCKET ssh-add -l | wc -l | tr -d ' ') _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"
fi 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() { find_live_gnome_keyring_agents() {
for i in $_GNOME_KEYRING_AGENT_SOCKETS; do for i in $_GNOME_KEYRING_AGENT_SOCKETS; do
test_agent_socket "$i" test_agent_socket "$i"
done done
} }
find_live_osx_keychain_agents() { find_live_osx_keychain_agents() {
for i in $_OSX_KEYCHAIN_AGENT_SOCKETS; do for i in $_OSX_KEYCHAIN_AGENT_SOCKETS; do
test_agent_socket "$i" test_agent_socket "$i"
done done
} }
find_live_gpg_agents() { find_live_gpg_agents() {
for i in $_GPG_AGENT_SOCKETS; do for i in $_GPG_AGENT_SOCKETS; do
test_agent_socket "$i" test_agent_socket "$i"
done done
} }
find_live_ssh_agents() { find_live_ssh_agents() {
for i in $_SSH_AGENT_SOCKETS; do for i in $_SSH_AGENT_SOCKETS; do
test_agent_socket "$i" test_agent_socket "$i"
done done
} }
function fingerprints() { function fingerprints() {
local file="$1" local file="$1"
while read -r l; do while read -r l; do
[[ -n $l && ${l###} == "$l" ]] && ssh-keygen -l -f /dev/stdin <<<"$l" [[ -n $l && ${l###} == "$l" ]] && ssh-keygen -l -f /dev/stdin <<<"$l"
done <"$file" done <"$file"
} }
find_all_agent_sockets() { find_all_agent_sockets() {
_SHOW_IDENTITY=0 _SHOW_IDENTITY=0
if [ "$1" = "-i" ]; then if [ "$1" = "-i" ]; then
_SHOW_IDENTITY=1 _SHOW_IDENTITY=1
fi fi
_LIVE_AGENT_LIST= _LIVE_AGENT_LIST=
find_all_ssh_agent_sockets find_all_ssh_agent_sockets
find_all_gpg_agent_sockets find_all_gpg_agent_sockets
find_all_gnome_keyring_agent_sockets find_all_gnome_keyring_agent_sockets
find_all_osx_keychain_agent_sockets find_all_osx_keychain_agent_sockets
find_live_ssh_agents find_live_ssh_agents
find_live_gpg_agents find_live_gpg_agents
find_live_gnome_keyring_agents find_live_gnome_keyring_agents
find_live_osx_keychain_agents find_live_osx_keychain_agents
_debug_print "$_LIVE_AGENT_LIST" _debug_print "$_LIVE_AGENT_LIST"
_LIVE_AGENT_LIST=$(echo "$_LIVE_AGENT_LIST" | tr ' ' '\n' | sort -n -t: -k 2 -k 1 | uniq) _LIVE_AGENT_LIST=$(echo "$_LIVE_AGENT_LIST" | tr ' ' '\n' | sort -n -t: -k 2 -k 1 | uniq)
_LIVE_AGENT_SOCK_LIST=() _LIVE_AGENT_SOCK_LIST=()
_debug_print "SORTED: $_LIVE_AGENT_LIST" _debug_print "SORTED: $_LIVE_AGENT_LIST"
if [[ $_SHOW_IDENTITY -gt 0 ]]; then if [[ $_SHOW_IDENTITY -gt 0 ]]; then
i=0 i=0
for a in $_LIVE_AGENT_LIST; do for a in $_LIVE_AGENT_LIST; do
sock=${a/:*/} sock=${a/:*/}
_LIVE_AGENT_SOCK_LIST[$i]=$sock _LIVE_AGENT_SOCK_LIST[$i]=$sock
# technically we could have multiple keys forwarded # technically we could have multiple keys forwarded
# But I haven't seen anyone do it # But I haven't seen anyone do it
akeys=$(SSH_AUTH_SOCK=$sock ssh-add -l) akeys=$(SSH_AUTH_SOCK=$sock ssh-add -l)
fingerprint=$(echo "${akeys}" | awk '{print $2}') fingerprint=$(echo "${akeys}" | awk '{print $2}')
if [ -e ~/.ssh/authorized_keys ]; then if [ -e ~/.ssh/authorized_keys ]; then
authorized_entry=$(fingerprints ~/.ssh/authorized_keys | grep "$fingerprint") authorized_entry=$(fingerprints ~/.ssh/authorized_keys | grep "$fingerprint")
fi fi
comment=$(echo "${authorized_entry}" | awk '{print $3,$4,$5,$6,$7}') 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" printf "export SSH_AUTH_SOCK=%s \t#%i) \t%s\n" "$sock" $((i + 1)) "$comment"
i=$((i + 1)) i=$((i + 1))
done done
else else
printf "%s\n" "$_LIVE_AGENT_LIST" | sed -e 's/ /\n/g' | sort -n -t: -k 2 -k 1 printf "%s\n" "$_LIVE_AGENT_LIST" | sed -e 's/ /\n/g' | sort -n -t: -k 2 -k 1
fi fi
} }
set_ssh_agent_socket() { set_ssh_agent_socket() {
if [ "$1" = "-c" ] || [ "$1" = "--choose" ]; then if [ "$1" = "-c" ] || [ "$1" = "--choose" ]; then
find_all_agent_sockets -i find_all_agent_sockets -i
if [ -z "$_LIVE_AGENT_LIST" ]; then if [ -z "$_LIVE_AGENT_LIST" ]; then
echo "No agents found" echo "No agents found"
return 1 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 fi
echo -n "Choose (1-${#_LIVE_AGENT_SOCK_LIST[@]})? " # set agent pid
read -r choice if [ -n "$SSH_AUTH_SOCK" ]; then
if [ -n "$choice" ]; then export SSH_AGENT_PID=$(($(echo "$SSH_AUTH_SOCK" | cut -d. -f2) + 1))
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 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 return 0
if [ -n "$SSH_AUTH_SOCK" ]; then
export SSH_AGENT_PID=$(($(echo "$SSH_AUTH_SOCK" | cut -d. -f2) + 1))
fi
return 0
} }
ssh-find-agent() { ssh-find-agent() {
if [ "$1" = "-c" ] || [ "$1" = "--choose" ]; then if [ "$1" = "-c" ] || [ "$1" = "--choose" ]; then
set_ssh_agent_socket -c set_ssh_agent_socket -c
return $? return $?
elif [ "$1" = "-a" ] || [ "$1" = "--auto" ]; then elif [ "$1" = "-a" ] || [ "$1" = "--auto" ]; then
set_ssh_agent_socket set_ssh_agent_socket
return $? return $?
else else
find_all_agent_sockets -i find_all_agent_sockets -i
return 0 return 0
fi fi
} }
# Automatically add ssh-agent to any new ssh connection # Automatically add ssh-agent to any new ssh connection
ssh-find-agent -a ssh-find-agent -a
if [ -z "$SSH_AUTH_SOCK" ]; then if [ -z "$SSH_AUTH_SOCK" ]; then
eval "$(ssh-agent)" >/dev/null eval "$(ssh-agent)" >/dev/null
ssh-add -l >/dev/null || alias ssh='ssh-add -l >/dev/null || ssh-add && unalias ssh; ssh' ssh-add -l >/dev/null || alias ssh='ssh-add -l >/dev/null || ssh-add && unalias ssh; ssh'
fi fi

View File

@ -7,29 +7,29 @@
# (or at least I want to try it) # (or at least I want to try it)
type paru >/dev/null 2>&1 && { type paru >/dev/null 2>&1 && {
# recreate the normal look of yay # recreate the normal look of yay
alias yay="paru --bottomup" alias yay="paru --bottomup"
} }
syu() { syu() {
type topgrade >/dev/null 2>&1 && { type topgrade >/dev/null 2>&1 && {
topgrade topgrade
return return
} }
type paru >/dev/null 2>&1 && { type paru >/dev/null 2>&1 && {
paru paru
return return
} }
type yay >/dev/null 2>&1 && { type yay >/dev/null 2>&1 && {
yay yay
return return
} }
type pacman >/dev/null 2>&1 && { type pacman >/dev/null 2>&1 && {
echo "Did not find paru, or yay installed. Updates will not be applied to aur packages." echo "Did not find paru, or yay installed. Updates will not be applied to aur packages."
sudo pacman -Syu sudo pacman -Syu
return return
} }
} }

View File

@ -1,5 +1,5 @@
#!/usr/bin/env sh #!/usr/bin/env sh
if [ ! "$DISPLAY" ] && [ -n "$XDG_VTNR" ] && [ "$XDG_VTNR" -eq 1 ]; then 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 fi

View File

@ -8,49 +8,49 @@ alias tmux="tmux -f ${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf"
# fzf # fzf
if exist fzf; then if exist fzf; then
# fzf select a tmux session to connect to, with pane preview # fzf select a tmux session to connect to, with pane preview
alias tm='_fzf_tmux_attach_start_session' alias tm='_fzf_tmux_attach_start_session'
alias tl=tm alias tl=tm
else else
alias tm='tmux_attach_start' alias tm='tmux_attach_start'
# show a list of running tmux sessions # show a list of running tmux sessions
alias tl='tmux list-sessions -F "#{session_name}" 2>/dev/null ' alias tl='tmux list-sessions -F "#{session_name}" 2>/dev/null '
fi fi
_fzf_tmux_list_sessions() { _fzf_tmux_list_sessions() {
tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf \ tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf \
--layout=reverse \ --layout=reverse \
--height=50% \ --height=50% \
--border \ --border \
--prompt="Session> " \ --prompt="Session> " \
--preview="tmux_pane_tree {}" \ --preview="tmux_pane_tree {}" \
--preview-window=right:80% \ --preview-window=right:80% \
--print-query --print-query
} }
_fzf_tmux_attach_start_session() { _fzf_tmux_attach_start_session() {
if [ -z "$1" ]; then if [ -z "$1" ]; then
result=$(_fzf_tmux_list_sessions) result=$(_fzf_tmux_list_sessions)
case "$?" in case "$?" in
0) 0)
# found a session, attaching # found a session, attaching
tmux_attach_start "$(echo "$result" | tail --lines=1)" tmux_attach_start "$(echo "$result" | tail --lines=1)"
;; ;;
1) 1)
# did not find a session, creating # did not find a session, creating
result=$(echo "$result" | head --lines=1) result=$(echo "$result" | head --lines=1)
# if . was only thing entered, create one for current dir # if . was only thing entered, create one for current dir
if [ "$result" = "." ]; then if [ "$result" = "." ]; then
tmux_attach_start tmux_attach_start
# create for query name # create for query name
else else
tmux_attach_start "$result" tmux_attach_start "$result"
fi fi
;; ;;
esac esac
else else
tmux_attach_start "$1" tmux_attach_start "$1"
fi fi
} }
unset choice unset choice