20231204-dot_matrix.md (8857B)
1 A user's dotfiles are sacred. I, like many others, try to maintain all of my custom configurations and scripts in a [git repo](https://gitlab.com/pyratebeard/dotfiles){target="_blank" rel="noreferrer"}. 2 3 This is a great when you need to build a new system, just clone and go. 4 5 I have a number of different systems that I clone my dotfiles onto - PC, laptop, [phone](https://log.pyratebeard.net/entry/20170614-termux_on_android.html){target="_blank" rel="noreferrer"}, and my servers. 6 7 All of these systems can be slightly different. Maybe I'm running a different OS, like OpenBSD, so commands or filepaths are dissimilar. To deal with this I would create a new branch as soon as I clone my repo specifically for that device and make any slight adjustments. 8 9 Over time I would modify or improve my dotfiles, but I wouldn't always push the changes straight away. I let things build up until I finally sit down, switch back to my main branch, and pick through the changes to push without including any device specific adjustments. 10 11 This is a pain. So I have decided to spend some time improving things meaning I can stick to my main branch on all devices. 12 13 #### off the chain 14 [b78637c91813483f9a9b80899c4f5d9ede5c14ed](https://git.pyratebeard.net/dotfiles/commit/b78637c91813483f9a9b80899c4f5d9ede5c14ed.html){target="_blank" rel="noreferrer"} 15 ``` 16 diff --git a/zsh/.zsh/keychain.zsh b/zsh/.zsh/keychain.zsh 17 @@ -1,13 +1,16 @@ 18 # KEYCHAIN 19 20 -# ssh key dir 21 -SSH_KEY_DIR="$HOME/.ssh" 22 +## don't run if keychain not installed (i.e a server) 23 +if command -v keychain >/dev/null ; then 24 + # ssh key dir 25 + SSH_KEY_DIR="$HOME/.ssh" 26 27 -GPG_TTY=$(tty) 28 -export GPG_TTY 29 + GPG_TTY=$(tty) 30 + export GPG_TTY 31 32 -# funtoo keychain 33 -eval $(keychain -q --agents gpg --nogui --eval 0xC7877C715113A16D) 34 -if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ] ; then 35 - export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)" 36 + # funtoo keychain 37 + eval $(keychain -q --agents gpg --nogui --eval 0xC7877C715113A16D) 38 + if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ] ; then 39 + export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)" 40 + fi 41 fi 42 ``` 43 44 On my servers I don't tend to need GPG but my zsh config includes running `keychain` to set up gpg agent when a terminal is started. I modified my _keychain.zsh_ file to only run if `keychain` is installed. 45 46 #### tmux, ahoy! 47 [8af62ecd9c7e44a77a11541b558fe1ca069a6e14](https://git.pyratebeard.net/dotfiles/commit/8af62ecd9c7e44a77a11541b558fe1ca069a6e14.html){target="_blank" rel="noreferrer"} 48 ``` 49 diff --git a/zsh/.zsh/welcome.zsh b/zsh/.zsh/welcome.zsh 50 @@ -1,4 +1,6 @@ 51 # WELCOME 52 +## don't run this if over ssh (i.e. a server) 53 +[[ -v SSH_TTY ]] && exit 0 54 55 PTS=$(ps -U $USER | awk '{ print $2 }' | grep "pts/" | uniq | wc -l) 56 57 @@ -24,4 +26,4 @@ tmux list-sessions >/dev/null 2>&1 || script 58 if [[ $TMUX_PANE == "%0" ]] && [[ ! -v VIMRUNTIME ]]; then 59 $HOME/bin/ahoy 60 fi 61 -cat ~/tmp/logo5 62 +#cat ~/tmp/logo5 63 ``` 64 65 My zsh setup also includes a script which starts `tmux` on the first terminal opened and then runs my custom `ahoy` script. Again, I don't want or need this on my servers so I modified it not to run over ssh. 66 67 My `ahoy` script works well on my main system but needs work to run without errors on my laptop. Mainly ignoring backups and mail local to my PC. 68 69 #### don't prompt me 70 [056f2d6ddfdab3b9345bd8dd7b65430defa8f0e2](https://git.pyratebeard.net/dotfiles/commit/056f2d6ddfdab3b9345bd8dd7b65430defa8f0e2.html){target="_blank" rel="noreferrer"} 71 ``` 72 diff --git a/zsh/.zsh/prompt.zsh b/zsh/.zsh/prompt.zsh 73 @@ -99,8 +99,11 @@ PROMPT='${USER_LEVEL}[${COLOR_NORMAL}%~${USER_LEVEL}]$(GIT_PROMPT)── - %f' 74 tiny) 75 #PROMPT='%F{3} %%${COLOR_NORMAL} ' 76 # change prompt colour if started from vim 77 -if [[ -v VIMRUNTIME || -v SSH_TTY ]] ; then 78 - PROMPT='%F{9} ──── ─${COLOR_NORMAL} ' 79 +if [[ -v VIMRUNTIME ]] ; then 80 + PROMPT='%F{13} ──── ─${COLOR_NORMAL} ' 81 +# change prompt to show hostname if over ssh 82 +elif [[ -v SSH_TTY ]] ; then 83 + PROMPT='%F{13} ${HOSTNAME}%F{3}_ ${COLOR_NORMAL}' 84 else 85 PROMPT='%F{11} ──── ─${COLOR_NORMAL} ' 86 fi 87 ``` 88 89 My (current) zsh prompt is pretty minimal, showing `──── ─` on the left then the filepath and git branch details on the right. For my servers I changed the prompt to show the hostname. Now I have configured the prompt to automatically change to the hostname if connecting over `ssh`. This is actually much nicer as my prompt was the same on my laptop and phone and sometimes I forgot if I was still in an `ssh` session. 90 91 For [a while](20221020-shell_shocked.html){target="_blank" rel="noreferrer"} now I have been making use of the terminal buffer in `vim` so set a different colour prompt for that. 92 93 94 #### hulk bash! 95 [9aa4aee5b7a121c0af42de4bf730e8f23e8166f8](https://git.pyratebeard.net/dotfiles/commit/9aa4aee5b7a121c0af42de4bf730e8f23e8166f8.html){target="_blank" rel="noreferrer"} 96 ``` 97 15 files changed, 69 insertions(+), 13 deletions(-) 98 ``` 99 100 This one is probably good practice anyway. Switching all my `#!/bin/bash` crashbangs to `#!/usr/bin/env bash` because some systems, like the BSDs, use a different filepath for `bash`. (69 insertions, nice! *snigger*) 101 102 #### moniker 103 [58fa110b56b090fbb378a16ad8df5a812588a20b](https://git.pyratebeard.net/dotfiles/commit/58fa110b56b090fbb378a16ad8df5a812588a20b.html){target="_blank" rel="noreferrer"} 104 ``` 105 diff --git a/zsh/.zsh/aliases.zsh b/zsh/.zsh/aliases.zsh 106 @@ -11,13 +11,19 @@ 107 # author ▓▒ pyratebeard 108 # code ▓▒ https://git.pyratebeard.net/dotfiles/file/zsh/.zsh/aliases.zsh.html 109 110 - alias sudo='sudo ' # hack to allow aliases with sudo 111 +# ▓▓▒░ root 112 +# check for doas so aliases can be used on different systems 113 +# add whitespace for hack to make aliases woth with {sudo,doas} 114 +command -v doas >/dev/null && \ 115 + alias sudo='doas ' || \ 116 + alias sudo='sudo ' 117 118 # ▓▓▒░ sys 119 120 [output ommitted] 121 122 # ▓▓▒░ fun(ctions) 123 @@ -219,6 +225,6 @@ 124 pandoc -s -t man "$*" | man -l - 125 } 126 127 - :q() { 128 - [[ -v SSH_TTY ]] && echo dumpshock || sudo systemctl poweroff 129 + :q!() { 130 + [[ -v SSH_TTY ]] && echo dumpshock || sudo halt -p 131 } 132 ``` 133 134 Aliases are important, there were a couple of changes required here. First some systems use `doas` instead of `sudo` so I put in a check for `doas` and if it exists I alias it to `sudo`. That way all my aliases that are configured to use `sudo` don't break. My shutdown function also had to be modified to work on any platform, so I switched to directly calling `halt`. 135 136 #### epithet 137 [255622b7c1b8e68529be337126bfdbd9575c609e](https://git.pyratebeard.net/dotfiles/commit/255622b7c1b8e68529be337126bfdbd9575c609e.html){target="_blank" rel="noreferrer"} 138 ``` 139 diff --git a/zsh/.zsh/aliases.zsh b/zsh/.zsh/aliases.zsh 140 @@ -18,10 +18,26 @@ command -v doas >/dev/null && \ 141 alias sudo='doas ' || \ 142 alias sudo='sudo ' 143 144 +# ▓▓▒░ unix 145 +# openbsd's ls(1) doesn't provide the `--color` option. 146 +# i have grown to like this and spent a long time 147 +# trying to find a work around, but none exists tiko. 148 +# so i succumbed to installing coreutils and doing this 149 +command -v gls >/dev/null && \ 150 + alias ls="gls -hF --color=auto" || \ 151 + alias ls="ls -hF --color=auto" 152 + 153 +# i also need dircolors(1) from coreutils for zsh autocompletion 154 +command -v gdircolors >/dev/null && alias dircolors="gdircolors" 155 + 156 +# i make use of some funky shit in my log makefiles 157 +# which isn't possible using the openbsd make(1) 158 +command -v gmake >/dev/null && alias make='gmake' 159 + 160 + 161 # ▓▓▒░ sys 162 ``` 163 164 More alias issues, this time with `ls`. I have grown to like colour output with `ls` but the OpenBSD package doesn't provide the `--color` option. I attempted to find a workaround but instead succumbed to installing the coreutils package which includes `gls`, and thus providing `--color`. I then check which package is installed to set my alias. 165 166 The same check is configured in my `chpwd_auto_cd` function as it didn't seem to pick up the alias. If you're interested, [this function](https://git.pyratebeard.net/dotfiles/file/zsh/.zsh/functions/chpwd_auto_cd.html){target="_blank" rel="noreferrer"} auto runs `ls` when I `cd` into a directory. 167 168 The coreutils package also gives me `gdircolors`, a substitute for `dircolors`, which is used in my zsh autocompletion settings. 169 170 #### mainland 171 These small changes mean I don't have to make device specific modifications to my dots, which in turn will (hopefully) help me to keep my repo more regularly updated. 172 173 There are still a few updates that required to make it close to perfect. As mentioned, my `ahoy` script doesn't run properly on any device other that my PC. 174 175 I also use a script for `tmux` on my laptop which displays battery information. I want to work on this and make it cross-device compatible. 176 177 How do you manage your dots across devices?