[Bin, Fish] Better handling of unknown executables

Only execute stuff if it is in PATH.
This commit is contained in:
Lucien Cartier-Tilet 2022-05-22 14:11:58 +02:00
parent beaea0bd66
commit 6feecc1fdc
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
2 changed files with 53 additions and 49 deletions

View File

@ -48,81 +48,85 @@ of said command running.
#+header: :wrap "src bash :exports code" #+header: :wrap "src bash :exports code"
#+BEGIN_SRC emacs-lisp :var table=autostart-table :cache yes #+BEGIN_SRC emacs-lisp :var table=autostart-table :cache yes
(mapconcat (lambda (start-command) (mapconcat (lambda (start-command)
(let* ((command (replace-regexp-in-string (regexp-quote "~") "" (nth 0 start-command))) (let* ((command (replace-regexp-in-string "~" "" (nth 0 start-command)))
(arguments (replace-regexp-in-string (regexp-quote "~") "" (nth 1 start-command))) (arguments (replace-regexp-in-string "~" "" (nth 1 start-command)))
(oncep (string= "yes" (nth 2 start-command))) (oncep (string= "yes" (nth 2 start-command)))
(full-command (replace-regexp-in-string " +" (full-command (replace-regexp-in-string
" +"
" " " "
(format "%s %s &" command arguments)))) (format "%s %s &" command arguments))))
(if oncep
(format (concat (format "which %s && %s"
(concat "if pgrep -x %s ; then\n" command
" echo \"%s already running\"\n" (if (not oncep)
full-command
(format (concat "if pgrep -x %s ; then\n"
" echo %s already running\n"
"else\n" "else\n"
" %s\n" " %s\n"
" disown\n" " disown\n"
"fi") "fi")
command command
command command
full-command) command
full-command))) full-command))))))
table table
"\n") "\n")
#+END_SRC #+END_SRC
#+RESULTS[97a97fceb694333615e59599d7c2d7fac52c5e8d]: autostart-gen #+RESULTS[64fcf7c33f989171bc7582495cd508959f4030c3]: autostart-gen
#+begin_src bash :exports code #+begin_src bash :exports code
pactl load-module module-switch-on-connect & which pactl && pactl load-module module-switch-on-connect &
mpc stop & which mpc && mpc stop &
xrdb -merge "$HOME"/.Xresources & which xrdb && xrdb -merge "$HOME"/.Xresources &
if pgrep -x picom ; then which picom && if pgrep -x picom ; then
echo "picom already running" echo picom already running
else else
picom --experimental-backends & picom
disown disown
fi fi
set-screens & which set-screens && set-screens &
if pgrep -x numlockx ; then which numlockx && if pgrep -x numlockx ; then
echo "numlockx already running" echo numlockx already running
else else
numlockx on & numlockx
disown disown
fi fi
if pgrep -x pumopm ; then which pumopm && if pgrep -x pumopm ; then
echo "pumopm already running" echo pumopm already running
else else
pumopm & pumopm
disown disown
fi fi
if pgrep -x xfce-polkit ; then which xfce-polkit && if pgrep -x xfce-polkit ; then
echo "xfce-polkit already running" echo xfce-polkit already running
else else
xfce-polkit & xfce-polkit
disown disown
fi fi
if pgrep -x nm-applet ; then which nm-applet && if pgrep -x nm-applet ; then
echo "nm-applet already running" echo nm-applet already running
else else
nm-applet & nm-applet
disown disown
fi fi
xwallpaper --zoom "$(cat "$HOME"/.cache/wallpaper)" & which xwallpaper && xwallpaper --zoom "$(cat "$HOME"/.cache/wallpaper)" &
if pgrep -x xss-lock ; then which xss-lock && if pgrep -x xss-lock ; then
echo "xss-lock already running" echo xss-lock already running
else else
xss-lock plock & xss-lock
disown disown
fi fi
if pgrep -x /usr/lib/kdeconnectd ; then which /usr/lib/kdeconnectd && if pgrep -x /usr/lib/kdeconnectd ; then
echo "/usr/lib/kdeconnectd already running" echo /usr/lib/kdeconnectd already running
else else
/usr/lib/kdeconnectd & /usr/lib/kdeconnectd
disown disown
fi fi
if pgrep -x dunst ; then which dunst && if pgrep -x dunst ; then
echo "dunst already running" echo dunst already running
else else
dunst & dunst
disown disown
fi fi
#+end_src #+end_src

View File

@ -62,7 +62,7 @@ Now, there is only one function I modify when it comes to the appearance of fish
when Im 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]]. when Im 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 #+BEGIN_SRC fish
function fish_greeting 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
#+END_SRC #+END_SRC