diff --git a/.config/autostart/copyq.desktop b/.config/autostart/copyq.desktop new file mode 100644 index 00000000..e10d514a --- /dev/null +++ b/.config/autostart/copyq.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Type=Application +Exec=env QT_QPA_PLATFORM=xcb /usr/bin/copyq +Hidden=false +NoDisplay=false +X-GNOME-Autostart-enabled=true +Name[en_US]=CopyQ +Name=CopyQ +Comment[en_US]= +Comment= +# https://copyq.readthedocs.io/en/latest/known-issues.html#on-linux-global-shortcuts-pasting-or-clipboard-monitoring-does-not-work diff --git a/.config/starship.toml b/.config/starship.toml index 28f6c144..9c376b53 100644 --- a/.config/starship.toml +++ b/.config/starship.toml @@ -59,6 +59,7 @@ symbol = '🌴 ' format = '\(on [$symbol$branch(:$remote_branch)]($style) ' [git_commit] +only_detached = false tag_disabled = false [git_status] diff --git a/.gitconfig b/.gitconfig index be933e57..5a1d918a 100644 --- a/.gitconfig +++ b/.gitconfig @@ -335,7 +335,7 @@ '" root-dir = rev-parse --show-toplevel save = !git add -A && git commit -m 'chore: commit save point' # from https://snyk.io/blog/10-git-aliases-for-faster-and-productive-git-workflow/ - st = status + st = status --ignored sync = "!$HOME/.gitconfig.d/git-sync.sh $@" type = cat-file -t undo = reset HEAD~1 --mixed # from https://snyk.io/blog/10-git-aliases-for-faster-and-productive-git-workflow/ @@ -383,6 +383,10 @@ lg3 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold yellow)(%ar)%C(reset)%C(auto)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all lg4 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset) %C(bold cyan)(committed: %cD)%C(reset) %C(auto)%d%C(reset)%n'' %C(white)%s%C(reset)%n'' %C(dim white)- %an <%ae> %C(reset) %C(dim white)(committer: %cn <%ce>)%C(reset)' ss = stash show + review-commits = "!f() {\n CURRENT=$(git branch --show-current);\n echo \"Current branch: $CURRENT\";\n printf \"Enter base branch (default: main): \";\n read -r BASE < /dev/tty;\n BASE=${BASE:-main};\n echo;\n COMMITS=$(git log --reverse --pretty=format:\"%H\" $BASE..$CURRENT);\n if [ -z \"$COMMITS\" ]; then\n echo \"No commits found in $CURRENT that aren't in $BASE\";\n return 0;\n fi;\n COUNT=$(echo \"$COMMITS\" | wc -l);\n printf \"Found %s commit(s) to review\\n\" \"$COUNT\";\n echo;\n i=1;\n for c in $COMMITS; do\n MSG=$(git log --format=%B -n 1 $c | head -1);\n AUTH=$(git log --format=\"%an\" -n 1 $c);\n DATE=$(git log --format=\"%ar\" -n 1 $c);\n echo \"═══════════════════════════════════════════════════════════════════\";\n echo \"Commit $i of $COUNT\";\n echo \"═══════════════════════════════════════════════════════════════════\";\n echo \"Commit: $c\";\n echo \"Author: $AUTH\";\n echo \"Date: $DATE\";\n echo \"Message: $MSG\";\n echo;\n git diff $c^..$c;\n echo;\n echo \"───────────────────────────────────────────────────────────────────\";\n if [ $i -lt $COUNT ]; then\n printf \"Press Enter to continue to next commit...\";\n read -r dummy < /dev/tty;\n echo;\n else\n echo \"Review complete!\";\n fi;\n i=$((i + 1));\n done;\n}; f" + wl = worktree list + wr = worktree remove + wta = "!f() {\n branch=\"$1\";\n repo=$(basename $(git worktree list --porcelain | grep -m1 \"^worktree\" | cut -d\" \" -f2));\n parent=$(dirname $(git worktree list --porcelain | grep -m1 \"^worktree\" | cut -d\" \" -f2));\n safe=$(echo \"$branch\" | tr \"/\" \"-\");\n worktree_path=\"${parent}/${repo}-${safe}\";\n if git show-ref --verify --quiet refs/heads/\"${branch}\"; then\n git worktree add \"${worktree_path}\" \"${branch}\";\n elif git show-ref --verify --quiet refs/remotes/origin/\"${branch}\"; then\n git worktree add -b \"${branch}\" \"${worktree_path}\" \"origin/${branch}\";\n else\n git worktree add -b \"${branch}\" \"${worktree_path}\" origin/HEAD;\n fi && printf \"Worktree created at: %s\\n\" \"$(echo \"${worktree_path}\" | sed \"s|^$HOME|~|\")\";\n}; f" [checkout] defaultRemote = origin [core] diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 2cae6250..7a32baaa 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -22,13 +22,7 @@ on: branches: - $GITHUB_BASE_REF #if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) - paths: - - '.github/workflows/pre-commit.yml' - - '.pre-commit-config.yaml' pull_request: - paths: - - '.github/workflows/pre-commit.yml' - - '.pre-commit-config.yaml' # from the example here: # https://docs.github.com/en/actions/examples/using-scripts-to-test-your-code-on-a-runner#example-workflow @@ -101,6 +95,8 @@ jobs: lint: runs-on: ubuntu-latest + permissions: + pull-requests: write steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 env: @@ -109,7 +105,7 @@ jobs: fetch-depth: $CHECKOUT_DEPTH - name: MegaLinter - uses: oxsecurity/megalinter/flavors/cupcake@7e042c726c68415475b05a65a686c612120a1232 # v7.7.0 + uses: oxsecurity/megalinter/flavors/cupcake@55a59b24a441e0e1943080d4a512d827710d4a9d # v9.2.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} MEGALINTER_CONFIG: ci/.mega-linter.yaml @@ -152,15 +148,21 @@ jobs: check-latest: true - name: Install python - uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0 + uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0 with: - python-version: '3.11' + python-version: '3.12' - - name: Run pre-commit on all files - uses: pre-commit/action@646c83fcd040023954eafda54b4db0192ce70507 # v3.0.0 + - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 with: - # this should run the pre-commit hooks only on the files changed between the default branch and the one in the PR - extra_args: --verbose -a + path: ~/.cache/pre-commit + # Key includes python version and config hash to invalidate cache on changes + key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} + + - name: Install pre-commit + run: pip install pre-commit + + - name: Run pre-commit + run: pre-commit run --show-diff-on-failure --color=always --all-files --verbose pre-commit: if: (!github.event.act) @@ -174,15 +176,21 @@ jobs: fetch-depth: $CHECKOUT_DEPTH - name: Install python - uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0 + uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0 with: - python-version: '3.11' + python-version: '3.12' - - name: Run pre-commit - uses: pre-commit/action@646c83fcd040023954eafda54b4db0192ce70507 # v3.0.0 + - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 with: - # this should run the pre-commit hooks only on the files changed between the default branch and the one in the PR - extra_args: --verbose --from-ref ${{ needs.get-changed-files.outputs.BASE_REF }} --to-ref HEAD + path: ~/.cache/pre-commit + # Key includes python version and config hash to invalidate cache on changes + key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} + + - name: Install pre-commit + run: pip install pre-commit + + - name: Run pre-commit + run: pre-commit run --show-diff-on-failure --color=always --all-files --verbose check-zshrc: runs-on: ubuntu-latest diff --git a/.shellrc.d/base b/.shellrc.d/base index 8380d72b..80b3804c 100644 --- a/.shellrc.d/base +++ b/.shellrc.d/base @@ -138,3 +138,17 @@ grep -q 10 /proc/sys/vm/swappiness || { vm.swappiness = 10 EOF } + +for ssh_socket_file in \ + "${HOME}/.1password/agent.sock" \ + "${HOME}/.bitwarden-ssh-agent.sock" \ + "${HOME}/snap/bitwarden/current/.bitwarden-ssh-agent.sock" \ + "${HOME}/.keeper-ssh-agent.sock" \ + ; do + if [[ -S "${ssh_socket_file}" ]]; then + # the default is 'export SSH_AUTH_SOCK=/run/user/1000/keyring/ssh' + # but use a password manager's socket file if it exists + export SSH_AUTH_SOCK="${ssh_socket_file}" + break + fi +done diff --git a/.shellrc.d/functions/blueconnect b/.shellrc.d/functions/blueconnect index 65356541..66294b07 100644 --- a/.shellrc.d/functions/blueconnect +++ b/.shellrc.d/functions/blueconnect @@ -48,7 +48,7 @@ blueconnect() { #amixer -D pulse sset Master mute bluetoothctl disconnect; } - if bluetoothctl connect $(bluetoothctl paired-devices | awk "tolower(\$0) ~ /${device}/ { print \$2 }"); then + if bluetoothctl connect $(bluetoothctl devices | awk "tolower(\$0) ~ /${device}/ { print \$2 }"); then [[ "${bluetooth_versions[${bluetooth_version}]%%.*}" -lt 5 ]] && { echo "turning volume back up..." #sleep 3 @@ -73,7 +73,7 @@ _blueconnect_completions() { if [[ "${#COMP_WORDS[@]}" -gt 2 ]]; then if [[ "${COMP_WORDS[1]}" =~ ^file$ ]]; then # output into columns all files tracked in the ${HOME_DIR} repo - VALUES="$(bluetoothctl paired-devices | cut -d' ' -f3-)" + VALUES="$(bluetoothctl devices | cut -d' ' -f3-)" fi elif [[ "${#COMP_WORDS[@]}" -eq 2 ]]; then # ${#COMP_WORDS} starts off at 2, so we're at the initial [Tab] diff --git a/.shellrc.d/functions/rsync-with-progress b/.shellrc.d/functions/rsync-with-progress index 5a4b614f..80e31b58 100644 --- a/.shellrc.d/functions/rsync-with-progress +++ b/.shellrc.d/functions/rsync-with-progress @@ -74,6 +74,7 @@ rsync-with-progress() { --recursive --links --perms + --times --group --owner --devices @@ -86,8 +87,6 @@ rsync-with-progress() { --hard-links --exclude='.trashed-*' --sparse - --no-times - --size-only ) declare -a RSYNC_FLAGS_NEGATIONS=( ) @@ -271,8 +270,8 @@ rsync-with-progress() { time ${SUDO} rsync "${RSYNC_FLAGS[@]}" "${SRC}" "${DST}" | pv --eta --line-mode --progress --size "${file_count}" } -# echo -n "do you want to skip updating times? [Y/n] "; read -# [[ ${REPLY} =~ ^n$ ]] || rsync_flags+=" --size-only" + echo -n "do you want to skip updating times? [Y/n] "; read + [[ ${REPLY} =~ ^n$ ]] || RSYNC_FLAGS+=(--size-only) if has pv && [[ ${PV_METHOD} -eq 1 && "${file_count}" -le 100 ]]; then diff --git a/.vimrc b/.vimrc index cc2aad85..ca761e3f 100644 --- a/.vimrc +++ b/.vimrc @@ -157,8 +157,11 @@ set history=4000 " hi; allow for ample command history ":so ~/.vim/extenders/.vim.wrap ":so ~/.vim/extenders/.vim.loadtemplate -set term=xterm " needed for the colorscheme to show as more bold and vibrant than 'screen.xterm-256color' -colorscheme ron +if version < 901 + " this block restricts the situations in which the following options are enabled + set term=xterm " needed for the colorscheme to show as more bold and vibrant than 'screen.xterm-256color' + colorscheme ron +endif syntax sync minlines=50 " ensure vim doesn't keep changing syntax highlighting; from @@ -332,9 +335,13 @@ nnoremap " " automatically install vim-plug " -let data_dir = has('nvim') ? stdpath('data') . '/site' : s:vim_home_dir -if empty(glob(data_dir . '/autoload/plug.vim')) - exe system('curl -fLo "' . s:vim_home_dir . '/autoload/plug.vim" --create-dirs +let data_dir = has('nvim') ? stdpath('data') . '/site/autoload' : s:vim_home_dir +if empty(data_dir) + exe system('mkdir -p ' . data_dir) +endif + +if empty(glob(data_dir . '/plug.vim')) + exe system('curl -sfLo "' . data_dir . '/plug.vim" --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim') autocmd VimEnter * PlugInstall --sync | source $MYVIMRC endif @@ -344,7 +351,7 @@ endif " plugins: " https://vimawesome.com/ -call plug#begin(s:vim_home_dir . '/plugged') +call plug#begin(data_dir . '/plugged') " Plug 'airblade/vim-gitgutter' " " Plug 'AndrewRadev/linediff.vim' " " Plug 'arp242/undofile_warn.vim' " @@ -354,8 +361,10 @@ call plug#begin(s:vim_home_dir . '/plugged') Plug 'ekalinin/Dockerfile.vim' " adds syntax highlighting for Dockerfiles " Plug 'ervandew/supertab' " smart tab completion (old) Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries', 'frozen': 'true' } " go development +" Plug 'glts/vim-textobj-comment' " Plug 'hashivim/vim-terraform' " syntax highlighting for terraform " Plug 'https://github.com/ElmCast/elm-vim' " + Plug 'github/copilot.vim' " Plug 'https://github.com/fevrin/AnsiEsc.vim', { 'frozen': 'true' } " converts ANSI escape codes to colors " Plug 'inkarkat/vim-AdvancedDiffOptions' " " Plug 'inkarkat/vim-ConflictMotions' " older conflict marker jumper @@ -364,7 +373,6 @@ call plug#begin(s:vim_home_dir . '/plugged') " Plug 'junegunn/fzf.vim' " Plug 'junegunn/vim-easy-align' " easily align lines based on a common character expression " Plug 'kana/vim-textobj-user' " -" Plug 'glts/vim-textobj-comment' " " Plug 'Konfekt/FastFold' " fixes slow folding " Plug 'mbbill/undotree' " lets you visualize a file's undo history " Plug 'mhinz/vim-signify' " @@ -395,9 +403,9 @@ call plug#begin(s:vim_home_dir . '/plugged') " Plug 'tpope/vim-surround' " adds commands for surrounding arbitrary text with tags, quotes, etc. Plug 'tpope/vim-unimpaired' " add handy mappings for toggling options, jumping, formatting, etc. " Plug 'vim-airline/vim-airline' " +" Plug 'Vimjas/vim-python-pep8-indent' " make python code comply with PEP8 recommendation " Plug 'vim-scripts/vcscommand.vim' " " Plug 'vim-syntastic/syntastic' " code syntax checker -" Plug 'Vimjas/vim-python-pep8-indent' " make python code comply with PEP8 recommendation Plug 'vito/booklit.vim' " syntax highlighting for Booklit files " Plug 'ycm-core/YouCompleteMe' " speedy code completion, comprehension, and refactoring engine " Plug 'yggdroot/indentline' " diff --git a/Makefile b/Makefile index a183ccad..66480b06 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ ifeq ($(notdir $(CURDIR)), .ssh) @if [ -d $(DIR) ]; then \ cp -ai $(TEMPLATE) $(CONFIG_FILE); \ - $(info going through all Include lines and replace them with the file contents) \ + $(info going through all Include lines and replacing them with the file contents) \ for line in $(shell grep -n Include $(TEMPLATE) | sed -re 's;Include ;;' | sort -r); do \ lineno=$${line%%:*}; \ file=$${line##*:}; \ @@ -52,7 +52,7 @@ ifeq ($(notdir $(CURDIR)), .gitconfig.d) @if [ -d $(DIR) ]; then \ cp -ai $(TEMPLATE) $(CONFIG_FILE); \ - $(info going through all 'include' lines and replace them with the file contents) \ + $(info going through all 'include' lines and replacing them with the file contents) \ for line in $(shell grep -n ^include $(TEMPLATE) | sed -re 's;^include ;;' | sort -r); do \ lineno=$${line%%:*}; \ file=$${line##*:}; \ @@ -217,7 +217,7 @@ lint-cleanup: ## Linting: Clean up any leftover docker continers from linting -@echo '=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=' -@echo -for container in $$(docker container ls -a --format='{{.Names}}' | grep -E '^act-'); do \ - docker container stop "$${container}"; \ + docker container stop --signal 9 "$${container}"; \ docker container rm "$${container}"; \ done && \ for volume in $$(docker volume ls --format='{{.Name}}' | grep -E '^act-'); do \ diff --git a/README.md b/README.md index 84ba28a5..36409359 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,10 @@ To run a specific job: gh act --rm -j lint -W .github/workflows/pre-commit.yml +To run jobs that use `actions/upload-artifact` and `actions/download-artifact`: + + gh act --artifact-server-path /tmp/artifacts -W .github/workflows/pre-commit.yml + ### Local `pre-commit` linting If `pip` is installed, `make pre-commit` will run all `pre-commit` hooks on all changed files. Note, however, that the `pre-commit` linting is a @@ -116,6 +120,6 @@ done ``` -[install `gh`]: https://github.com/cli/cli#installation -[install `nektos/act`]: https://github.com/nektos/act#installation +[install `gh`]: https://github.com/cli/cli/blob/trunk/docs/install_linux.md#debian-ubuntu-linux-raspberry-pi-os-apt +[install `nektos/act`]: https://nektosact.com/installation/gh.html [install docker]: https://docs.docker.com/get-docker/ diff --git a/README.md.tpl b/README.md.tpl index 7589d7f6..f87e1167 100644 --- a/README.md.tpl +++ b/README.md.tpl @@ -61,6 +61,10 @@ To run a specific job: gh act --rm -j lint -W .github/workflows/pre-commit.yml +To run jobs that use `actions/upload-artifact` and `actions/download-artifact`: + + gh act --artifact-server-path /tmp/artifacts -W .github/workflows/pre-commit.yml + ### Local `pre-commit` linting If `pip` is installed, `make pre-commit` will run all `pre-commit` hooks on all changed files. Note, however, that the `pre-commit` linting is a @@ -89,6 +93,6 @@ done ``` -[install `gh`]: https://github.com/cli/cli#installation -[install `nektos/act`]: https://github.com/nektos/act#installation +[install `gh`]: https://github.com/cli/cli/blob/trunk/docs/install_linux.md#debian-ubuntu-linux-raspberry-pi-os-apt +[install `nektos/act`]: https://nektosact.com/installation/gh.html [install docker]: https://docs.docker.com/get-docker/ diff --git a/ci/.cspell.json b/ci/.cspell.json deleted file mode 100644 index 24c63309..00000000 --- a/ci/.cspell.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "ignorePaths": [ - "**.sw*" - ], - "language": "en-US", - "words": [ - "Aftertabs", - "Architectrure", - "autoload", - "bsdextrautils", - "centralised", - "checkmake", - "CHECKMAKE", - "containerised", - "EDITMSG", - "elif", - "envsubst", - "esac", - "gettext", - "gsub", - "hadolint", - "infosec", - "javac", - "markdownlint", - "MARKDOWNLINT", - "metacharacters", - "minimise", - "minphony", - "mksh", - "mktemp", - "nektos", - "nullary", - "OIFS", - "pipenv", - "pkgs", - "Plzik", - "Proto", - "RACI", - "readarray", - "runbook", - "runbooks", - "sanitised", - "shellcheck", - "SHELLCHECK", - "shellcheckrc", - "shellrc", - "shfmt", - "SHFMT", - "shfmt's", - "sonarqube", - "SPOF", - "statefile", - "toplevel", - "usecases" - ] -} diff --git a/ci/.mega-linter.yaml b/ci/.mega-linter.yaml index b427891d..7e702743 100644 --- a/ci/.mega-linter.yaml +++ b/ci/.mega-linter.yaml @@ -42,7 +42,7 @@ MARKDOWN_MARKDOWNLINT_CONFIG_FILE: ci/.markdownlint.yaml REPOSITORY_CHECKOV_ARGUMENTS: '--skip-check CKV_GHA_7' REPOSITORY_CHECKOV_CONFIG_FILE: ci/.checkov.yaml -SPELL_CSPELL_CONFIG_FILE: ci/.cspell.json +SPELL_CSPELL_CONFIG_FILE: ci/cspell.yaml SPELL_LYCHEE_CONFIG_FILE: ci/lychee.toml diff --git a/ci/cspell.yaml b/ci/cspell.yaml new file mode 100644 index 00000000..debcc7ec --- /dev/null +++ b/ci/cspell.yaml @@ -0,0 +1,65 @@ +ignorePaths: + - '**.sw*' + +language: en-US + +# Enabled dictionaries +dictionaries: + - technical + - software-terms + - shell + - project + +words: + - Aftertabs + - Architectrure + - autoload + - bitwarden + - bsdextrautils + - centralised + - checkmake + - CHECKMAKE + - containerised + - EDITMSG + - elif + - envsubst + - esac + - gettext + - gsub + - hadolint + - infosec + - javac + - markdownlint + - MARKDOWNLINT + - metacharacters + - minimise + - minphony + - mksh + - mktemp + - nektos + - nullary + - OIFS + - pipenv + - pkgs + - Plzik + - Proto + - RACI + - readarray + - runbook + - runbooks + - sanitised + - shellcheck + - SHELLCHECK + - shellcheckrc + - shellrc + - shfmt + - SHFMT + - shfmt's + - sonarqube + - SPOF + - statefile + - toplevel + - unmute + - usecases + - vimdiff + - worktree diff --git a/ci/lychee.toml b/ci/lychee.toml index 6110565a..61b60bf9 100644 --- a/ci/lychee.toml +++ b/ci/lychee.toml @@ -93,6 +93,7 @@ exclude = [ '^https://web\.archive\.org/web/', '[0-9]+\+[^@]+@users.noreply.github.com', 'https://www\.reddit\.com/r/golang/comments/n628db/go_install_fails_with_can_only_use_pathversion', + 'https://(www\.)?stackoverflow\.com/.*', ] # Exclude these filesystem paths from getting checked. diff --git a/etc/pm/sleep.d/10_change_theme b/etc/pm/sleep.d/10_change_theme new file mode 100755 index 00000000..d5c6add7 --- /dev/null +++ b/etc/pm/sleep.d/10_change_theme @@ -0,0 +1,81 @@ +#!/usr/bin/env bash + +# this must be copied to /etc/pm/sleep.d/ +# that should automatically copy it to /lib/systemd/system-sleep/change_theme +# +# ensure both files also have 755 perms + +PM_ACTION="${1}" +DARK_THEME='Yaru-viridian-dark' +LIGHT_THEME='Yaru-viridian' +DARK_START=18 +DARK_STOP=7 +export DBUS_SESSION_BUS_ADDRESS='unix:path=/run/user/1000/bus' + +log() { + echo "$(date '+%F %T %Z') ${*}" +} + +set_theme() { + theme_type="${1:-dark}" + color_scheme="prefer-${theme_type}" + + if [[ "${theme_type}" =~ ^dark$ ]]; then + theme="${DARK_THEME}" + elif [[ "${theme_type}" =~ ^light$ ]]; then + theme="${LIGHT_THEME}" + else + echo "error: theme-type must be 'light' or 'dark'" + return 1 + fi + + { + log "gsettings set org.gnome.desktop.interface color-scheme '${color_scheme}'" + log "gsettings set org.gnome.desktop.interface gtk-theme ${theme}" + log "gsettings set org.gnome.gedit.preferences.editor scheme ${theme}" + } >>/tmp/theme.log + gsettings set org.gnome.desktop.interface color-scheme "${color_scheme}" + gsettings set org.gnome.desktop.interface gtk-theme "${theme}" + gsettings set org.gnome.gedit.preferences.editor scheme "${theme}" +} + +{ + echo + log "running $0" +} >>/tmp/theme.log + +# set the dark theme if run during the dark theme hours + +# normally, cron should run this file +# if this file is in /etc/pm/sleep.d/, this will also trigger when waking from sleep/hibernation +if [[ + "${PM_ACTION}" =~ ^(thaw|resume)$ || + -z "${PM_ACTION}" + ]]; then + + if [[ "${DARK_START}" -gt "${DARK_STOP}" ]]; then + if [[ + "$(date +%H)" -ge "${DARK_START}" && + "$(date +%H)" -le 23 + ]] || [[ + "$(date +%H)" -ge 00 && + "$(date +%H)" -lt "${DARK_STOP}" + ]]; then + set_theme dark + else + set_theme light + fi + else + if [[ + "$(date +%H)" -ge "${DARK_STOP}" && + "$(date +%H)" -le 23 + ]] || [[ + "$(date +%H)" -ge 00 && + "$(date +%H)" -lt "${DARK_START}" + ]]; then + set_theme light + else + set_theme dark + fi + fi +fi diff --git a/home/.ssh/config.d/dns b/home/.ssh/config.d/dns new file mode 100644 index 00000000..02b9f3f0 --- /dev/null +++ b/home/.ssh/config.d/dns @@ -0,0 +1,9 @@ +#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# +# DNS # +#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# + +# add static host entries to save on DNS resolution, which can shaves off a few seconds every connection +Host jump, jump-alt + Hostname 1.1.1.1 + # Hostname jump.hostname.com + # Hostname jump-alt.hostname.com diff --git a/home/.ssh/config.d/general_config b/home/.ssh/config.d/general_config new file mode 100644 index 00000000..fadc0c88 --- /dev/null +++ b/home/.ssh/config.d/general_config @@ -0,0 +1,51 @@ +#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# +# General config # +#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# + + +# for certain devices +Host *-abc* + User root + +# for other devices +Host us-east-01-prod*a + Ciphers aes256-cbc,aes192-cbc,aes128-cbc,3des-cbc + +# for all devices +Host *-ac* + User admn + HostKeyAlgorithms +ssh-dss + KexAlgorithms +diffie-hellman-group1-sha1 + PreferredAuthentications password,keyboard-interactive + +Host *.internal.hostname.com *.otherhost.com + IdentitiesOnly yes + IdentityFile ~/.ssh/id_rsa + +Host github.com + Hostname github.com + User git + IdentityFile ~/.ssh/github_specific_key + +Host bitbucket.org + Hostname bitbucket.org + User git + IdentityFile ~/.ssh/bitbucket_specific_key + +Host gitlab.com + Hostname gitlab.com + User git + IdentityFile ~/.ssh/gitlab_specific_key + +Host * + ForwardAgent yes + PreferredAuthentications publickey,password,keyboard-interactive + ServerAliveInterval 5 + ServerAliveCountMax 9 + GSSAPIAuthentication no + StrictHostKeyChecking accept-new + UserKnownHostsFile=/dev/null + LogLevel error +# ControlMaster auto +# ControlPath ~/.ssh/%r@%h:%p +# ControlPersist 120 diff --git a/home/.ssh/config.d/hostname_rewrites b/home/.ssh/config.d/hostname_rewrites new file mode 100644 index 00000000..b839da82 --- /dev/null +++ b/home/.ssh/config.d/hostname_rewrites @@ -0,0 +1,20 @@ +#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# +# Hostname rewrites # +#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# + +# these shortened Hostname values work only since jump, which is always used as the proxy, searches the "internal.hostname.com" domain +# otherwise, we'd have to specify the full "%h.$region.internal.hostname.com" for each stanza +Host us-east-1* + Hostname %h.us-east-1 + +Host eu-west-3* + Hostname %h.eu-west-3 + +# for switches +Host *-switch* sa-east-1-dev* !*.somehost.com + Hostname %h.somehost.com +# ProxyCommand ssh -t %r@jump -W %h:%p + +# complete hostnames +Host *us-east-1* *eu-west-3* !*.internal.hostname.com !github.com !*.somehost.com + Hostname %h.internal.hostname.com diff --git a/home/.ssh/config.d/proxy_host_configs b/home/.ssh/config.d/proxy_host_configs new file mode 100644 index 00000000..4dab24b3 --- /dev/null +++ b/home/.ssh/config.d/proxy_host_configs @@ -0,0 +1,16 @@ +#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# +# Proxy host configs # +#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# + +# Match host works in more cases than Host for re-parsed hostnames +Match host *labcomp*,!*jump*,!1.2.*.* + ProxyCommand ssh jump.us-east-1 -W %h:%p +# # ProxyJump passes along ssh flags, like `-vvv`, to the jump host, but requires a static username to use with the jump host if different from the +# # final host +# ProxyJump %r@jump.us-east-1 +# ProxyCommand ssh %r@jump.us-east-1 -W %h:%p + +# Match host works in more cases than Host for re-parsed hostnames +Match host *.internal.hostname.com,*.somehost.com,!*jump* + ProxyCommand ssh jump -W %h:%p +# ProxyJump %r@jump diff --git a/home/.ssh/config.template b/home/.ssh/config.template new file mode 100644 index 00000000..672c7559 --- /dev/null +++ b/home/.ssh/config.template @@ -0,0 +1,7 @@ +Include config.d/dns + +Include config.d/hostname_rewrites + +Include config.d/proxy_host_configs + +Include config.d/general_config diff --git a/lib/systemd/system-sleep/change_theme b/lib/systemd/system-sleep/change_theme index 828ab925..1a4f1137 100755 --- a/lib/systemd/system-sleep/change_theme +++ b/lib/systemd/system-sleep/change_theme @@ -2,33 +2,80 @@ # REPLACE "\$(id -u)" WITH YOUR USER ID # REPLACE "\$(id -un)" WITH YOUR USERNAME +# +# afterward, copy this to /lib/systemd/system-sleep/change_theme +# +# ensure it also has 755 perms and is owned by root -PM_ACTION="${1}" +set -x +set -euo pipefail + +# enable for debugging in journalctl +#exec &> >(logger -t change_theme) + +PM_ACTION="${1:-}" DARK_THEME='Yaru-viridian-dark' LIGHT_THEME='Yaru-viridian' DARK_START=18 DARK_STOP=7 export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/\$(id -u)/bus" # may be needed for cron to run when logged out +log() { + echo "$(date '+%F %T %Z') ${*}" + logger -t change_theme "${*}" +} + +set_theme() { + theme_type="${1:-dark}" + color_scheme="prefer-${theme_type}" + + if [[ "${theme_type}" =~ ^dark$ ]]; then + theme="${DARK_THEME}" + prefer_dark_theme=1 + elif [[ "${theme_type}" =~ ^light$ ]]; then + theme="${LIGHT_THEME}" + prefer_dark_theme=0 + else + log "error: theme-type must be 'light' or 'dark'" + return 1 + fi + + { + log "gsettings set org.gnome.desktop.interface color-scheme '${color_scheme}'" + log "gsettings set org.gnome.desktop.interface gtk-theme ${theme}" + } + + if [[ "${PM_ACTION}" =~ ^post$ ]]; then + /bin/su "\$(id -un)" -c "gsettings set org.gnome.desktop.interface color-scheme '${color_scheme}'" + /bin/su "\$(id -un)" -c "gsettings set org.gnome.desktop.interface gtk-theme '${theme}'" + + for i in /home/"\$(id -un)"/.config/gtk-*/settings.ini; do + /bin/su "\$(id -un)" -c "sed -i_$(date '+%F_%T_%Z') -Ee 's;^(gtk-application-prefer-dark-theme=)[0-9]$;\1'${prefer_dark_theme}';' $i;" + done + else + gsettings set org.gnome.desktop.interface color-scheme "${color_scheme}" + gsettings set org.gnome.desktop.interface gtk-theme "${theme}" + + for i in /home/"$(id -un)"/.config/gtk-*/settings.ini; do + sed -i_$(date '+%F_%T_%Z') -Ee 's;^(gtk-application-prefer-dark-theme=)[0-9]$;\1'${prefer_dark_theme}';' $i + done + fi +} + +{ + echo + log "running $0" +} + # set the dark theme if run during the dark theme hours # normally, cron should run this file # if this file is in /lib/systemd/system-sleep/ (/etc/pm/sleep.d/ doesn't work), this will also trigger when waking from sleep/hibernation in Ubuntu if [[ - "${PM_ACTION}" =~ ^post$ || - -z "${PM_ACTION}" + "$(date +%H)" -ge "${DARK_START}" || + "$(date +%H)" -lt "${DARK_STOP}" ]]; then - if [[ - "$(date +%H)" -ge "${DARK_START}" || - "$(date +%H)" -lt "${DARK_STOP}" - ]]; then - # the full command paths may not be necessary - /bin/su "\$(id -un)" -c "/usr/bin/gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'" - /bin/su "\$(id -un)" -c "/usr/bin/gsettings set org.gnome.desktop.interface gtk-theme ${DARK_THEME}" - /bin/su "\$(id -un)" -c "/usr/bin/gsettings set org.gnome.gedit.preferences.editor scheme ${DARK_THEME}" - else - /bin/su "\$(id -un)" -c "/usr/bin/gsettings set org.gnome.desktop.interface color-scheme 'prefer-light'" - /bin/su "\$(id -un)" -c "/usr/bin/gsettings set org.gnome.desktop.interface gtk-theme ${LIGHT_THEME}" - /bin/su "\$(id -un)" -c "/usr/bin/gsettings set org.gnome.gedit.preferences.editor scheme ${LIGHT_THEME}" - fi + set_theme dark +else + set_theme light fi