[Bin] Fish to bash autostart, fix some bash issues

Autostart is now written in Bash.

Autostart now loads a module to automatically switch devices for
PipeWire/PulseAudio when a new one is connected.

Fix some issues with using "$@" instead of "$*"
See Shellcheck’s SC2148
This commit is contained in:
Lucien Cartier-Tilet 2022-02-26 15:40:15 +01:00
parent e1077bad9a
commit c0f6bbc5a7
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA

View File

@ -17,7 +17,7 @@ from this file to the actual executables.
* Autostart * Autostart
:PROPERTIES: :PROPERTIES:
:HEADER-ARGS: :shebang "#!/usr/bin/env fish" :mkdirp yes :tangle ~/.local/bin/autostart :HEADER-ARGS: :shebang "#!/usr/bin/env bash" :mkdirp yes :tangle ~/.local/bin/autostart
:CUSTOM_ID: Autostart-a99e99e7 :CUSTOM_ID: Autostart-a99e99e7
:END: :END:
Because I sometimes switch from window manager to window manager, creating a Because I sometimes switch from window manager to window manager, creating a
@ -29,7 +29,8 @@ of said command running.
~set-screens~ is a custom script declared [[*set-screens][below]]. ~set-screens~ is a custom script declared [[*set-screens][below]].
#+NAME: autostart-table #+NAME: autostart-table
| Command | Arguments | Run once? | | Command | Arguments | Run once? |
|-------------+-------------------------------------+-----------| |-------------+------------------------------------------+-----------|
| ~pactl~ | ~load-module module-switch-on-connect~ | |
| ~mpc~ | ~stop~ | no | | ~mpc~ | ~stop~ | no |
| ~picom~ | ~--experimental-backends~ | yes | | ~picom~ | ~--experimental-backends~ | yes |
| ~set-screens~ | | no | | ~set-screens~ | | no |
@ -37,20 +38,28 @@ of said command running.
| ~pumopm~ | | yes | | ~pumopm~ | | yes |
| ~xfce-polkit~ | | yes | | ~xfce-polkit~ | | yes |
| ~nm-applet~ | | yes | | ~nm-applet~ | | yes |
| ~xwallpaper~ | ~--zoom (cat $HOME/.cache/wallpaper)~ | no | | ~xwallpaper~ | ~--zoom "$(cat "$HOME"/.cache/wallpaper)"~ | no |
| ~xss-lock~ | ~plock~ | yes | | ~xss-lock~ | ~plock~ | yes |
| ~xrdb~ | ~-merge $HOME/.Xresources~ | no | | ~xrdb~ | ~-merge "$HOME"/.Xresources~ | no |
#+NAME: autostart-gen #+NAME: autostart-gen
#+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 (regexp-quote "~") "" (nth 0 start-command)))
(arguments (replace-regexp-in-string (regexp-quote "~") "" (nth 1 start-command))) (arguments (replace-regexp-in-string (regexp-quote "~") "" (nth 1 start-command)))
(oncep (string= "yes" (nth 2 start-command)))) (oncep (string= "yes" (nth 2 start-command))))
(if oncep (if oncep
(format "pgrep -x %s 2&>/dev/null || echo (%s) 2&>/dev/null" (format
(concat "if pgrep -x %s ; then\n"
" echo \"%s already running\"\n"
"else\n"
" %s &\n"
" disown\n"
"fi")
command command
(replace-regexp-in-string " +" " " (format "%s %s & && disown" command
(replace-regexp-in-string " +" " " (format "%s %s"
command command
arguments))) arguments)))
(format "%s %s &" command arguments)))) (format "%s %s &" command arguments))))
@ -58,34 +67,59 @@ of said command running.
"\n") "\n")
#+END_SRC #+END_SRC
#+RESULTS[6246524876f7d46a8649c951a1145302c603bc78]: autostart-gen #+RESULTS[337fc252540623d17d47dc7e0661840db2a4eab5]: autostart-gen
#+begin_example #+begin_src bash :exports code
pactl load-module module-switch-on-connect &
mpc stop & mpc stop &
pgrep -x picom 2&>/dev/null || echo (picom --experimental-backends & && disown) 2&>/dev/null if pgrep -x picom ; then
echo "picom already running"
else
picom --experimental-backends &
disown
fi
set-screens & set-screens &
pgrep -x numlockx 2&>/dev/null || echo (numlockx on & && disown) 2&>/dev/null if pgrep -x numlockx ; then
pgrep -x pumopm 2&>/dev/null || echo (pumopm & && disown) 2&>/dev/null echo "numlockx already running"
pgrep -x xfce-polkit 2&>/dev/null || echo (xfce-polkit & && disown) 2&>/dev/null else
pgrep -x nm-applet 2&>/dev/null || echo (nm-applet & && disown) 2&>/dev/null numlockx on &
xwallpaper --zoom (cat $HOME/.cache/wallpaper) & disown
pgrep -x xss-lock 2&>/dev/null || echo (xss-lock plock & && disown) 2&>/dev/null fi
xrdb -merge $HOME/.Xresources & if pgrep -x pumopm ; then
#+end_example echo "pumopm already running"
else
pumopm &
disown
fi
if pgrep -x xfce-polkit ; then
echo "xfce-polkit already running"
else
xfce-polkit &
disown
fi
if pgrep -x nm-applet ; then
echo "nm-applet already running"
else
nm-applet &
disown
fi
xwallpaper --zoom "$(cat "$HOME"/.cache/wallpaper)" &
if pgrep -x xss-lock ; then
echo "xss-lock already running"
else
xss-lock plock &
disown
fi
xrdb -merge "$HOME"/.Xresources &
#+end_src
I also have an external sound card, a Scarlet 2i2 G3, that I would like to use I also have an external sound card, a Scarlet 2i2 G3, that I would like to use
as my default audio output. However, it might not be always connected, hence the as my default audio output. However, it might not be always connected, hence the
following code: following code:
#+NAME: default-soundcard # #+NAME: default-soundcard
#+BEGIN_SRC fish :tangle no # #+BEGIN_SRC fish
set SOUNDCARD "alsa_output.usb-Focusrite_Scarlett_2i2_USB_Y8KJ6NH094EF1C-00.analog-stereo" # # set SOUNDCARD "alsa_output.usb-Focusrite_Scarlett_2i2_USB_Y8KJ6NH094EF1C-00.analog-stereo"
pactl list short sinks | grep $SOUNDCARD 2&> /dev/null && pactl set-default-sink $SOUNDCARD # # pactl list short sinks | grep $SOUNDCARD 2&> /dev/null && pactl set-default-sink $SOUNDCARD
#+END_SRC # #+END_SRC
#+BEGIN_SRC fish :noweb yes
set -l PATH $PATH /usr/lib/xfce-polkit
<<autostart-gen()>>
<<default-soundcard>>
#+END_SRC
* Screen utilities * Screen utilities
:PROPERTIES: :PROPERTIES:
@ -625,7 +659,7 @@ adjust_device
:HEADER-ARGS: :shebang "#!/bin/bash" :mkdirp yes :tangle ~/.local/bin/dired :HEADER-ARGS: :shebang "#!/bin/bash" :mkdirp yes :tangle ~/.local/bin/dired
:END: :END:
#+BEGIN_SRC bash #+BEGIN_SRC bash
emacsclient -c -a emacs -e "(dired \"$@\")" emacsclient -c -a emacs -e "(dired \"$*\")"
#+END_SRC #+END_SRC
** Emacsmail ** Emacsmail
@ -636,7 +670,7 @@ emacsclient -c -a emacs -e "(dired \"$@\")"
This short script is used in my =~/.local/share/applications/mu4e.desktop= file This short script is used in my =~/.local/share/applications/mu4e.desktop= file
in order to send to Emacs any ~mailto:~ requests made in my system. in order to send to Emacs any ~mailto:~ requests made in my system.
#+BEGIN_SRC bash #+BEGIN_SRC bash
emacsclient -c -n -a emacs -e "(browse-url-mail \"$@\")" emacsclient -c -n -a emacs -e "(browse-url-mail \"$*\")"
#+END_SRC #+END_SRC
* Media * Media