From 6feecc1fdc50a9ac2df18a0079d38df4f7a6f9bc Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Sun, 22 May 2022 14:11:58 +0200 Subject: [PATCH] [Bin, Fish] Better handling of unknown executables Only execute stuff if it is in PATH. --- org/config/bin.org | 100 +++++++++++++++++++++++--------------------- org/config/fish.org | 2 +- 2 files changed, 53 insertions(+), 49 deletions(-) diff --git a/org/config/bin.org b/org/config/bin.org index 2dfab19..0efd010 100644 --- a/org/config/bin.org +++ b/org/config/bin.org @@ -48,81 +48,85 @@ of said command running. #+header: :wrap "src bash :exports code" #+BEGIN_SRC emacs-lisp :var table=autostart-table :cache yes (mapconcat (lambda (start-command) - (let* ((command (replace-regexp-in-string (regexp-quote "~") "" (nth 0 start-command))) - (arguments (replace-regexp-in-string (regexp-quote "~") "" (nth 1 start-command))) - (oncep (string= "yes" (nth 2 start-command))) - (full-command (replace-regexp-in-string " +" - " " - (format "%s %s &" command arguments)))) - (if oncep - (format - (concat "if pgrep -x %s ; then\n" - " echo \"%s already running\"\n" - "else\n" - " %s\n" - " disown\n" - "fi") - command - command - full-command) - full-command))) + (let* ((command (replace-regexp-in-string "~" "" (nth 0 start-command))) + (arguments (replace-regexp-in-string "~" "" (nth 1 start-command))) + (oncep (string= "yes" (nth 2 start-command))) + (full-command (replace-regexp-in-string + " +" + " " + (format "%s %s &" command arguments)))) + + (concat (format "which %s && %s" + command + (if (not oncep) + full-command + (format (concat "if pgrep -x %s ; then\n" + " echo %s already running\n" + "else\n" + " %s\n" + " disown\n" + "fi") + command + command + command + full-command)))))) table "\n") #+END_SRC -#+RESULTS[97a97fceb694333615e59599d7c2d7fac52c5e8d]: autostart-gen +#+RESULTS[64fcf7c33f989171bc7582495cd508959f4030c3]: autostart-gen #+begin_src bash :exports code -pactl load-module module-switch-on-connect & -mpc stop & -xrdb -merge "$HOME"/.Xresources & -if pgrep -x picom ; then - echo "picom already running" +which pactl && pactl load-module module-switch-on-connect & +which mpc && mpc stop & +which xrdb && xrdb -merge "$HOME"/.Xresources & +which picom && if pgrep -x picom ; then + echo picom already running else - picom --experimental-backends & + picom disown fi -set-screens & -if pgrep -x numlockx ; then - echo "numlockx already running" +which set-screens && set-screens & +which numlockx && if pgrep -x numlockx ; then + echo numlockx already running else - numlockx on & + numlockx disown fi -if pgrep -x pumopm ; then - echo "pumopm already running" +which pumopm && if pgrep -x pumopm ; then + echo pumopm already running else - pumopm & + pumopm disown fi -if pgrep -x xfce-polkit ; then - echo "xfce-polkit already running" +which xfce-polkit && if pgrep -x xfce-polkit ; then + echo xfce-polkit already running else - xfce-polkit & + xfce-polkit disown fi -if pgrep -x nm-applet ; then - echo "nm-applet already running" +which nm-applet && if pgrep -x nm-applet ; then + echo nm-applet already running else - nm-applet & + nm-applet disown fi -xwallpaper --zoom "$(cat "$HOME"/.cache/wallpaper)" & -if pgrep -x xss-lock ; then - echo "xss-lock already running" +which xwallpaper && xwallpaper --zoom "$(cat "$HOME"/.cache/wallpaper)" & +which xss-lock && if pgrep -x xss-lock ; then + echo xss-lock already running else - xss-lock plock & + xss-lock disown fi -if pgrep -x /usr/lib/kdeconnectd ; then - echo "/usr/lib/kdeconnectd already running" +which /usr/lib/kdeconnectd && if pgrep -x /usr/lib/kdeconnectd ; then + echo /usr/lib/kdeconnectd already running else - /usr/lib/kdeconnectd & + /usr/lib/kdeconnectd disown fi -if pgrep -x dunst ; then - echo "dunst already running" +which dunst && if pgrep -x dunst ; then + echo dunst already running else - dunst & + dunst disown fi #+end_src diff --git a/org/config/fish.org b/org/config/fish.org index ffabdbf..d561b32 100644 --- a/org/config/fish.org +++ b/org/config/fish.org @@ -62,7 +62,7 @@ Now, there is only one function I modify when it comes to the appearance of fish when I’m the one using it: the ~fish_greeting~ function. I use it to display the output of [[https://labs.phundrak.com/phundrak/pumo-system-info][a utility I wrote]]. #+BEGIN_SRC fish function fish_greeting - which pumo-system-info 2&> /dev/null && pumo-system-info || df -H | grep -v Filesystem | sort -rk 5 + which pumo-system-info 2&> /dev/null && pumo-system-info end #+END_SRC