From 99a3c0d31445fbd1139009848e402e982accf22b Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 10 Jan 2023 15:37:45 +0100 Subject: [PATCH 1/6] sh: Add conditionals to plugin loading --- office/.config/sh/alias.d/taskwarrior.sh | 2 +- terminal/.config/zsh/.zshrc | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/office/.config/sh/alias.d/taskwarrior.sh b/office/.config/sh/alias.d/taskwarrior.sh index 45cb0ae..96ac796 100644 --- a/office/.config/sh/alias.d/taskwarrior.sh +++ b/office/.config/sh/alias.d/taskwarrior.sh @@ -14,7 +14,7 @@ t() { # copy the `task` zsh completions over to my little alias 😉 # this is not very pretty and not super portable (needs ps) but # works for now. from here: https://unix.stackexchange.com/a/72564/414758 -if [ "$(ps -p $$ -o comm --no-headers)" = "zsh" ]; then compdef t=task; fi +if exist task && [ "$(ps -p $$ -o comm --no-headers)" = "zsh" ]; then compdef t=task; fi # Make taskopen XDG conforming. If changing here, also change in taskrc alias. alias taskopen='taskopen --config=${XDG_CONFIG_HOME:-~/.config}/task/taskopenrc' diff --git a/terminal/.config/zsh/.zshrc b/terminal/.config/zsh/.zshrc index e92d653..d403f19 100644 --- a/terminal/.config/zsh/.zshrc +++ b/terminal/.config/zsh/.zshrc @@ -18,12 +18,12 @@ compinit # End of lines added by compinstall # load plugins -PLUG_FOLDER="/usr/share/zsh/plugins" -source /usr/share/oh-my-zsh/plugins/colored-man-pages/colored-man-pages.plugin.zsh -source /usr/share/oh-my-zsh/plugins/command-not-found/command-not-found.plugin.zsh -source /usr/share/fzf/key-bindings.zsh +[ -e /usr/share/oh-my-zsh/plugins/colored-man-pages/colored-man-pages.plugin.zsh ] && source /usr/share/oh-my-zsh/plugins/colored-man-pages/colored-man-pages.plugin.zsh +[ -e /usr/share/oh-my-zsh/plugins/command-not-found/command-not-found.plugin.zsh ] && source /usr/share/oh-my-zsh/plugins/command-not-found/command-not-found.plugin.zsh +[ -e /usr/share/fzf/key-bindings.zsh ] && source /usr/share/fzf/key-bindings.zsh #source /usr/share/nvm/init-nvm.sh ## find the correct installed tab-completion version +PLUG_FOLDER="/usr/share/zsh/plugins" [ -e $PLUG_FOLDER/fzf-tab/fzf-tab.plugin.zsh ] && source $PLUG_FOLDER/fzf-tab/fzf-tab.plugin.zsh [ -e $PLUG_FOLDER/fzf-tab-bin-git/fzf-tab.plugin.zsh ] && source $PLUG_FOLDER/fzf-tab-bin-git/fzf-tab.plugin.zsh # these need to be sourced after fzf-tab From 274cc8026a523a1de7d425cbb2e8f4c9ea4c7a44 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 10 Jan 2023 16:47:16 +0100 Subject: [PATCH 2/6] sh: Add distrobox alias and enable displaying host Add a simple alias to quickly use distrobox with `db` alias, and modify pure prompt initialization slightly so that it displays a hostname when in a distrobox container (akin to operating from ssh or normal container usage). HACKY implementation makes use of both an internal pure prompt api (see here https://github.com/sindresorhus/pure/issues/585) and a distrobox env var that I am not sure how exposed it is either. Powerlevel10k uses a similar method though, so maybe it is fine (see here https://github.com/romkatv/powerlevel10k/blob/33916e91a743a73472a15f3fc27dd0aa9f7abbdf/internal/p10k.zsh#L8336). --- sh/.config/sh/alias | 5 +++++ terminal/.config/zsh/.zshrc | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/sh/.config/sh/alias b/sh/.config/sh/alias index b67408e..c71d8f4 100644 --- a/sh/.config/sh/alias +++ b/sh/.config/sh/alias @@ -119,3 +119,8 @@ elif exist ipython; then elif exist python; then alias py=python fi + +# distrobox +if exist distrobox; then + alias db=distrobox +fi diff --git a/terminal/.config/zsh/.zshrc b/terminal/.config/zsh/.zshrc index d403f19..4efb1d8 100644 --- a/terminal/.config/zsh/.zshrc +++ b/terminal/.config/zsh/.zshrc @@ -66,6 +66,10 @@ promptinit prompt_newline='%666v' # show git stash status as a ≡ zstyle :prompt:pure:git:stash show yes +# show hostname if we are in a distrobox environment +if [ -n "$DISTROBOX_ENTER_PATH" ] && [ -f /run/.containerenv ]; then + local container=lxc +fi prompt pure # shellcheck source=alias From 369345880d00ef2091c644465e0da41dad8c273f Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 12 Jan 2023 22:55:18 +0100 Subject: [PATCH 3/6] taskwarrior: Extend active task listing alias Extended active task listing to show both the active task from taskwarrior, but also any currently 'tracking' task from timewarrior. Ideally, those should be the same - but if they mismatch or timwarrrior is not correctly tracking the active task, this is still good information to have at a glance. --- office/.config/sh/alias.d/taskwarrior.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/office/.config/sh/alias.d/taskwarrior.sh b/office/.config/sh/alias.d/taskwarrior.sh index 96ac796..99a8262 100644 --- a/office/.config/sh/alias.d/taskwarrior.sh +++ b/office/.config/sh/alias.d/taskwarrior.sh @@ -26,7 +26,11 @@ alias tan="task annotate" alias tn="task next +READY" alias tun="task next urgency \> 4" -alias tra="task active" +if exist timew; then + alias tra="task active && timew" +else + alias tra="task active" +fi alias trw="task end.after:today-1wk completed" alias tad="task +ACTIVE done" From 0a867ee9929fe29b5ac49617b9d07315fcd109b2 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 12 Jan 2023 22:56:51 +0100 Subject: [PATCH 4/6] nvim: Add fix last spelling mistake mapping Added a quick way to fix the last spelling mistake: Use while writing (in insert mode) or localleader-s while in normal mode. It will fix the mistake and keep your cursor at the current position. --- nvim/.config/nvim/lua/maps.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nvim/.config/nvim/lua/maps.lua b/nvim/.config/nvim/lua/maps.lua index 7c889a0..c0a1c41 100644 --- a/nvim/.config/nvim/lua/maps.lua +++ b/nvim/.config/nvim/lua/maps.lua @@ -198,13 +198,14 @@ map.i.nore.silent['@@'] = 'u:CiteRef' -- map cc to insert a complete citation at cursor -- SPELL CHECKING --- Spell check set to O, 'o' for 'orthography': -- Move to the prev/next spelling error with [S ]S -- Move to the prev/next spelling error or suggestion with [s ]s -map.n.nore['ZZ'] = ':setlocal spell! spelllang=en_us,de_de' -map.n.nore['ZE'] = ':setlocal spell! spelllang=en_us' -map.n.nore['ZG'] = ':setlocal spell! spelllang=en_us' -map.n.nore['zz'] = '1z=' +map.n.nore['ZZ'] = ':setlocal spell! spelllang=en_us,de_de' +map.n.nore['ZE'] = ':setlocal spell! spelllang=en_us' +map.n.nore['ZG'] = ':setlocal spell! spelllang=de_de' +-- undo last spelling mistake from insert and normal mode +map.i.nore[''] = 'u[s1z=`]au' +map.n.nore['s'] = 'ms[s1z=`s' -- pp to comPile a document (or file, works for some languages like go/python/c) -- o to open the resulting document (mostly for pdfs) From d09584e69020878e9e9b20baadab88d04cce783b Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 13 Jan 2023 00:04:21 +0100 Subject: [PATCH 5/6] scripts: Remove compile script Never used the compile script for years now, and I neither see that changing nor the files being of any use anymore. They were something I whipped up when I first started getting into Linux and bash scripting (and as such a little nostalgic I suppose) but nothing that has actual purpose anymore. --- nvim/.config/nvim/lua/maps.lua | 9 --- .../nvim/plugin/personal/doccompile.vim | 25 ------- scripts/.local/bin/compile | 70 ------------------- scripts/.local/bin/open-compiled | 28 -------- 4 files changed, 132 deletions(-) delete mode 100644 nvim/.config/nvim/plugin/personal/doccompile.vim delete mode 100755 scripts/.local/bin/compile delete mode 100755 scripts/.local/bin/open-compiled diff --git a/nvim/.config/nvim/lua/maps.lua b/nvim/.config/nvim/lua/maps.lua index c0a1c41..5b43433 100644 --- a/nvim/.config/nvim/lua/maps.lua +++ b/nvim/.config/nvim/lua/maps.lua @@ -207,15 +207,6 @@ map.n.nore['ZG'] = ':setlocal spell! spelllang=de_de' map.i.nore[''] = 'u[s1z=`]au' map.n.nore['s'] = 'ms[s1z=`s' --- pp to comPile a document (or file, works for some languages like go/python/c) --- o to open the resulting document (mostly for pdfs) --- po to comPile *and* open a doc --- and all the same in uppercase for verbose output -map.n.nore['dp'] = ':DocCompile' -map.n.nore['dP'] = ':DocCompile!' -map.n.nore['do'] = ':DocOpen' -map.n.nore['dO'] = ':DocOpen!' - -- PLUGIN: easy-align -- Start interactive EasyAlign in visual mode (e.g. vipga) map.x['ga'] = '(EasyAlign)' diff --git a/nvim/.config/nvim/plugin/personal/doccompile.vim b/nvim/.config/nvim/plugin/personal/doccompile.vim deleted file mode 100644 index 83d361b..0000000 --- a/nvim/.config/nvim/plugin/personal/doccompile.vim +++ /dev/null @@ -1,25 +0,0 @@ -function s:_compile(verbose, ...) - :execute(":w!") - if a:verbose - execute "!" . "compile" . " " . "\"%:p\"" . " " . join(a:000) - else - silent execute "!" . "compile" . " " . "\"%:p\"" . " " . join(a:000) - endif -endfunction - -function s:_open(verbose, ...) - if a:verbose - execute "!" . "open-compiled" . " " . "\"%\"" . " " . join(a:000) - else - silent execute "!" . "open-compiled" . " " . "\"%\"" . " " . join(a:000) - endif -endfunction - -function s:_compileopen(verbose, ...) - call s:_compile(a:verbose, join(a:000)) - call s:_open(a:verbose, join(a:000)) -endfunction - -command -bang -nargs=* DocCompile call s:_compile(0, ) -command -bang -nargs=* DocCompileOpen call s:_compileopen(0, ) -command -bang -nargs=* DocOpen call s:_open(0, ) diff --git a/scripts/.local/bin/compile b/scripts/.local/bin/compile deleted file mode 100755 index 4a38bc7..0000000 --- a/scripts/.local/bin/compile +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env sh - -# from https://github.com/LukeSmithxyz/voidrice/blob/master/.local/bin/compiler -# -# This script will compile or run another finishing operation on a document. I -# have this script run via vim. -# -# Compiles .tex. groff (.mom, .ms), .rmd, .md. Opens .sent files as sent -# presentations. Runs scripts based on extention or shebang -# -# Expects the file to compile as first argument. -# Desired output format(s) can be specified in optional arguments following. - -file=$1 -if [ ! -f "$file" ]; then - echo "File does not exist." - exit 1 -else - printf "file: %s\n" "$file" -fi - -if [ "$#" -gt 1 ]; then - shift - formats="$*" -fi - -dir=$(dirname "$file") -base="${file%.*}" - -cd "$dir" || exit - -textype() { - if (sed 5q "$file" | grep -i -q 'xelatex') && exist xelatex; then - command="xelatex" - elif exist pdflatex; then - command="pdflatex" - fi - $command --output-directory="$dir" "$base" && - grep -i addbibresource "$file" >/dev/null && - biber --input-directory "$dir" "$base" && - $command --output-directory="$dir" "$base" && - $command --output-directory="$dir" "$base" -} - -sendtoRmd() { - printf "formats: %s\n" "$formats" - ## FIXME this is horribly inefficient, should just pass all formats to R - # but R expects them as "strings" and I don't know how to quote the individual words - if [ -n "$formats" ]; then - for fmt in $formats; do - exist R critical && echo "require(rmarkdown); render('$1', c(\"$fmt\"))" | R -q --vanilla - done - else - exist R critical && echo "require(rmarkdown); render('$1')" | R -q --vanilla - fi -} - -case "$file" in -*\.ms) refer -PS -e "$file" | groff -me -ms -kept -T pdf >"$base".pdf ;; -*\.mom) refer -PS -e "$file" | groff -mom -kept -T pdf >"$base".pdf ;; -*\.[0-9]) refer -PS -e "$file" | groff -mandoc -T pdf >"$base".pdf ;; -*\.[Rr]md | *\.md | *\.mkd | *\.markdown) sendtoRmd "$file" "$formats" ;; -*\.tex) textype "$file" ;; -*config.h) sudo make install ;; -*\.c) cc "$file" -o "$base" && "$base" ;; -*\.py) python "$file" ;; -*\.go) go run "$file" ;; -*\.sent) setsid sent "$file" 2>/dev/null &;; -*) sed 1q "$file" | grep "^#!/" | sed "s/^#!//" | xargs -r -I % "$file" ;; -esac diff --git a/scripts/.local/bin/open-compiled b/scripts/.local/bin/open-compiled deleted file mode 100755 index 489180b..0000000 --- a/scripts/.local/bin/open-compiled +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env sh - -# opout: "open output": A general handler for opening a file's intended output, -# usually the pdf of a compiled document. I find this useful especially -# running from vim. -# -# from https://github.com/LukeSmithxyz/voidrice/tree/master/.local/bin - -basename="$(echo "$1" | sed 's/\.[^\/.]*$//')" - -openCompiledDoc() { - if [ -f "$basename".pdf ]; then - setsid "$FILEREADER" "$basename.pdf" - elif [ -f "$(echo "$basename" | sed 's/ /-/g')".pdf ]; then - setsid "$FILEREADER" "$(echo "$basename" | sed 's/ /-/g').pdf" - elif [ -f "$(echo "$basename" | sed 's/ /_/g')".pdf ]; then - setsid "$FILEREADER" "$(echo "$basename" | sed 's/ /_/g').pdf" - elif [ -f "$basename".html ]; then - setsid "$BROWSER" "$basename.html" - fi -} - -case "$1" in - # *.tex|*.md|*.rmd|*.ms|*.me|*.mom) setsid "$FILEREADER" "$basename".pdf >/dev/null 2>&1 & ;; - *.tex|*.md|*.[Rr]md|*.ms|*.me|*.mom) openCompiledDoc >/dev/null 2>&1 & ;; - *.[0-9]) openCompiledDoc >/dev/null 2>&1 & ;; - *.html) openCompiledDoc >/dev/null 2>&1 & ;; -esac From bf8d6fb8a36f8c67eb3ab8fab0c805a3495b60b0 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 13 Jan 2023 00:05:40 +0100 Subject: [PATCH 6/6] scripts: Update README Updated readme a little for the new, changed and remaining scripts in the module. --- scripts/README.md | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index e57d3a9..b6e91dd 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -2,28 +2,59 @@ The scripts module contains several small shell scripts which did not fit under any specific module. Many of these modules are older and either 'legacy' in that they work but should be restructured at some point, -or perhaps not working at all anymore. +or perhaps not working at all anymore. It's a bit of a messy module. Some will work for others without needing changes, some are very personalized to me. +## archive + +An 'archiving' script, but not intended for backups. It will instead hardlink all files you give it in a single 'archive' directory, so even if you delete the original file from your directories, the hardlinked copy will remain. + +I use it to build a small archive of (mostly youtube videos) that I can delete from my normal folders but always quickly search through and grab again whenever I need them. Will probably not be too useful for most other purposes. + ## benchmark `benchmark` allows you to take the time another commands needs to run. It will simply output the time taken, and can be run repeatedly or averaged to get more accurate readings. -## compile +## bemenu-translate -`compile` is somewhat of a left-over script. -It should be refactored and moved into the `bibtex` module at some point. -It takes a filename and tries to invoke the corresponding compiler and is mainly used by my `pandoc` (or `rmarkdown`) workflow. -`open-compiled` is somewhat of a companion script which attempts to open the resulting file for the user. +`bemenu-translate` is a pretty useful tool if you are often writing in a non-native language, doing translation work or similar. In effect, it's a simple wrapper around `trans`, allowing you to use bemenu to input what you want translated and showing the output through the menu as well. + +Very useful to have as a little dropdown which you can call via global shortcut. ## lockscreen -`lockscreen` does just that, invoke the i3 lock-screen program with some simple defaults and a color. - +`lockscreen` does just that, invoking i3lock/waylock program with some simple defaults and a color, as well as stopping any running media and muting the audio. ## nomie `nomie` logs a simple journal entry in the open source habit-tracking app [nomie](https://nomie.app). To do this it needs an api key, which is, as of now, hard-coded to be sourced from my pass app. + +## powermenu + +A menu to invoke power-related commands: Shut down your PC, reboot, log out, sleep and suspend. Very simple, very useful. + +## sharefile + +This one could be useful to many: Quickly upload any file to `http://0x0.st` and get the link on your clipboard. +Can take the file to upload through stdin, as an argument, or be chosen interactively with fzf. + +## uoeia + +Helps you open images, especially remote ones, in your favorite image viewer. Point it at a link and it will open many different kinds of pictures, galleries, and so on. + +## vidl + +Helps you download videos (mostly from youtube) and archive them using the archive script above. +I use it to download interesting looking videos into an inbox for later viewing. + +## wallcrop.sh + +Probably not too useful for most: Takes an image that is exactly 3840x1080 pixels and cuts it in half, +naming the resulting images `xy_l.png` and `xy_r.png`. I use it to quickly cut multi-monitor wallpapers to a good display size. + +## wallr + +Allows you to read articles from your wallabag instance in the terminal. Pretty simple wrapper for the wallabag-cli python library (which is a requirement). Lists your articles using fzf by default and can mark them read if you wish.