This script will start a conky if it's not running; if it is running, it will kill it.
Useful for keybindings; as the same keybinding will either start or stop the conky.
It takes the name of the conky config file as an argument.
Please note to use it, you must call your script "toggleconky.sh"; this is due to the grep declaring the PID variable: we only want the line output of ps that has the actual running conky.
Agree, Conky is made to be seen. But this is Linux, and you do it because you can
Actually wrote the script for when I was developing lua conkys....I'd create the occaisional bug (not often, most of my code is bug free ) and lua would start dumping reams of stdout....it was easy to just use my toggleconky.sh to stop it and start it again...."!!" became my friend.
I have a section of my monitor now for "wildcard" conkys. I can choose which one I want there and use my keybindings to display it (or kill it).
The script actually morphed from a similar use case where I needed to start/stop a process from a keybinding (because its a headless computer governed by a flirc remote). The tricky part is getting all the grep/regex to extract the PID so you can execute kill.
Like the "killall" suggestion...when I was a wee lad, all I had was "kill".
A couple simple fish shell abbreviations for the lazy ones like me:
.dots
abbr -a .dots -r '\.{3,}.*' --position anywhere -f _abbr_dots
function _abbr_dots
string match -qr '\.\.(?<dots>\.+)(?<rest>.*)' -- $argv
echo ..(string replace -a '.' '/..' -- $dots)$rest
end
Allows to shorten repeated leading ../ with multiple dots also when entering a filename, e.g. micro .../file.txt expands to micro ../../file.txt.
.conf
abbr -a .conf -r '~~.*' --position anywhere -f _abbr_conf
function _abbr_conf
test -n "$XDG_CONFIG"
and set -l cfg $XDG_CONFIG
or set -l cfg ~/.config
set -q _abbr_conf_tab # skip expanding the shortcuts on tab completion
or switch $argv # shortcuts for frequently used files and dirs
case '~~f' ; set argv '~~fish'
case '~~fc' ; set argv '~~fish/config.fish'
case '~~fcd' ; set argv '~~fish/conf.d'
case '~~ffn' ; set argv '~~fish/functions'
case '~~fa' ; set argv (status -f) # this file
case '~~s' ; set argv '~~sway'
case '~~ss' ; set argv '~~sway/scripts'
case '~~scd' ; set argv '~~sway/config.d'
case '~~w' ; set argv '~~waybar'
case '~~wc' ; set argv '~~waybar/config'
case '~~ws' ; set argv '~~waybar/scripts'
case '~~wss' ; set argv '~~waybar/style.css'
case '~~grub' ; set argv '/etc/default/grub' # shortcuts do not need to be in .config
end
set -e _abbr_conf_tab
string replace -r '^~~' $cfg/ -- $argv |string replace -r ^$HOME/ '~/'; or true
# reset status in case the path wasn't in $HOME and the second replace failed
end~~~
Allows to shorten ~/.config[/name] with ~~[name], where 'name' can also be one of the configured shortcuts (the case statement and _abbr_conf_tab can be removed if no shortcuts are desired).
Note that Ctrl-Space can be used to avoid expanding, and Ctrl-Z to undo the expansion after the fact.
File completion won't work until after expansion, which is somewhat annoying.
I see no downside in binding / and tab to also first expand abbreviations though:
bind / expand-abbr self-insert
bind \t expand-abbr complete # or (to skip shortcuts on tab completion):
bind \t 'set _abbr_conf_tab; commandline -f expand-abbr; commandline -f complete'
# NOTE: 'set _abbr_conf_tab' expand-abbr complete does not work
and, why not (unrelated):
bind \e 'commandline -P; and commandline -f cancel; or commandline -f kill-whole-line'
Note: bindings (especially \t) may be ignored depending where they are issued, e.g. in conf.d.