summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmin Bandali <bandali@kelar.org>2024-04-01 15:21:11 -0400
committerAmin Bandali <bandali@kelar.org>2024-04-01 15:21:11 -0400
commit22a270eba9568af1394a46429f1a379200496cf9 (patch)
tree03a1de7c3719fa58c1c6c3fbefe77a94014592e1
parent1d18d65c2b6260f6e58d1cdf974ccb13d59cbf9d (diff)
downloadconfigs-22a270eba9568af1394a46429f1a379200496cf9.tar.gz
configs-22a270eba9568af1394a46429f1a379200496cf9.tar.xz
configs-22a270eba9568af1394a46429f1a379200496cf9.zip
Break pulse volume code out of bar and into its own script
In part so that it could easily be used in Emacs as well. Also rename pacify-pulseaudio to b-pacify (as in PAcify).
Diffstat (limited to '')
-rw-r--r--.config/sway/config4
-rw-r--r--.emacs.d/init.el113
-rwxr-xr-x.local/bin/b-bar13
-rwxr-xr-x.local/bin/b-pacify (renamed from .local/bin/pacify-pulseaudio)0
-rwxr-xr-x.local/bin/b-pavols23
-rwxr-xr-x.local/bin/my-bar20
6 files changed, 48 insertions, 125 deletions
diff --git a/.config/sway/config b/.config/sway/config
index 5e1334f..c251a25 100644
--- a/.config/sway/config
+++ b/.config/sway/config
@@ -155,7 +155,7 @@ bar {
position bottom
# status_command while date +'%a, %d %b %Y %T %z'; do sleep 1; done
- status_command my-bar
+ status_command b-bar
colors {
statusline #ffffff
@@ -191,7 +191,7 @@ for_window [app_id="firefox" title="Sharing Indicator"] \
exec mako >/tmp/mako.log 2>&1
exec dbus-update-activation-environment DISPLAY WAYLAND_DISPLAY SWAYSOCK
exec gsettings set 'org.gnome.desktop.interface' cursor-theme 'DMZ-White'
-exec pacify-pulseaudio
+exec b-pacify
exec [ -x "$(command -v nm-applet)" ] && nm-applet
include ~/.config/sway/"$(hostname)"
diff --git a/.emacs.d/init.el b/.emacs.d/init.el
index 9286e0c..f4bb031 100644
--- a/.emacs.d/init.el
+++ b/.emacs.d/init.el
@@ -219,66 +219,16 @@ plain variables. This means that `setopt' will execute any
(setopt battery-mode-line-format " [%b%p%% %t]")
(display-battery-mode))
-(progn ; display system volume in mode-line
- (defvar b/volume-level 0)
- (defvar b/volume-mute nil)
- (defvar b/volume-level-mic 0)
- (defvar b/volume-mute-mic nil)
-
- (defun b/volume-get (&optional use-default-source)
- "Get the default sink volume and mute state.
-If USE-DEFAULT-SOURCE is non-nill, use the default source (e.g. a
-microphone) instead of the default sink."
- (pcase (split-string ; expecting: <mute> <volume> (e.g. true 15)
- (string-trim
- (shell-command-to-string
- (mapconcat
- #'identity
- `("pamixer"
- ,(when use-default-source "--default-source")
- "--get-volume"
- "--get-mute")
- " "))))
- (`(,m ,v)
- (let ((mute (string= "true" m))
- (volume (string-to-number v)))
- `(,mute ,volume)))))
-
- (defun b/volume-update ()
- "Update system sound volume as displayed in mode-line."
- (let ((changed))
- (pcase (b/volume-get)
- (`(,mute ,volume)
- (unless (eq mute b/volume-mute)
- (setq b/volume-mute mute
- changed t))
- (unless (= volume b/volume-level)
- (setq b/volume-level volume
- changed t))))
- (pcase (b/volume-get 'mic)
- (`(,mute ,volume)
- (unless (eq mute b/volume-mute-mic)
- (setq b/volume-mute-mic mute
- changed t))
- (unless (= volume b/volume-level-mic)
- (setq b/volume-level-mic volume
- changed t))))
- (when changed
- (force-mode-line-update))))
-
- (defvar b/volume-timer (run-at-time nil 5 #'b/volume-update))
-
- (setq-default
+(progn ; display system volume and mute states in mode-line
+ (defsubst b/pavols ()
+ "Get volume and mute state of default pulseaudio sink and source."
+ ;; <sink_volume><sink_unmuted>,<source_volume><source_unmuted>
+ ;; e.g. 46+,89-
+ (string-trim (shell-command-to-string "b-pavols")))
+ (setopt
mode-line-format
- (append
- mode-line-format
- '((:eval
- (format
- " [%s%%%%%s %s%%%%%s]"
- (number-to-string b/volume-level)
- (if b/volume-mute "-" "+")
- (number-to-string b/volume-level-mic)
- (if b/volume-mute-mic "-" "+")))))))
+ `(,@mode-line-format
+ (:eval (format " [%s]" (b/pavols))))))
;; (with-eval-after-load 'fringe
;; ;; smaller fringe
@@ -502,42 +452,6 @@ for all frames."
(completing-read "Find recent file: " recentf-list)))
(b/keymap-global-set "C-c f r" #'b/recentf-open))
-;; (define-key minibuffer-local-completion-map
-;; "\t" #'minibuffer-force-complete)
-
-;; (with-eval-after-load 'icomplete
-
-;; (setq icomplete-on-del-error-function #'abort-recursive-edit)
-
-;; (defun b/icomplete-fido-backward-updir ()
-;; "Delete char before or go up directory, like `ido-mode'."
-;; (interactive)
-;; (if (and (eq (char-before) ?/)
-;; (eq (icomplete--category) 'file))
-;; (save-excursion
-;; (goto-char (1- (point)))
-;; (when (search-backward "/" (point-min) t)
-;; (delete-region (1+ (point)) (point-max))))
-;; (condition-case nil
-;; (call-interactively #'delete-backward-char)
-;; (error
-;; (when icomplete-on-del-error-function
-;; (funcall icomplete-on-del-error-function))))))
-
-;; (define-key icomplete-fido-mode-map
-;; (kbd "DEL") #'b/icomplete-fido-backward-updir))
-
-;; (fido-mode 1)
-;; (defun b/icomplete--fido-mode-setup ()
-;; "Customizations to `fido-mode''s minibuffer."
-;; (when (and icomplete-mode (icomplete-simple-completing-p))
-;; (setq-local
-;; ;; icomplete-compute-delay 0.1
-;; ;; icomplete-hide-common-prefix t
-;; icomplete-separator " ยท "
-;; completion-styles '(basic substring partial-completion flex))))
-;; (add-hook 'minibuffer-setup-hook #'b/icomplete--fido-mode-setup 1)
-
(with-eval-after-load 'eshell
(setopt
eshell-hist-ignoredups t
@@ -702,13 +616,6 @@ for all frames."
(b/keymap-set m "b" #'help-go-back)
(b/keymap-set m "f" #'help-go-forward)))
-(with-eval-after-load 'tramp
- (setopt tramp-auto-save-directory (b/emacs.d "tramp-auto-save/"))
- (add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
- (add-to-list 'tramp-default-proxies-alist '("localhost" nil nil))
- (add-to-list 'tramp-default-proxies-alist
- (list (regexp-quote (system-name)) nil nil)))
-
(with-eval-after-load 'doc-view
(b/keymap-set doc-view-mode-map "M-RET" #'image-previous-line))
@@ -1121,7 +1028,7 @@ for all frames."
(setopt
message-elide-ellipsis "[...]\n"
- message-citation-line-format "%N writes:\n"
+ message-citation-line-format "%N wrote:\n"
message-citation-line-function
#'message-insert-formatted-citation-line
message-confirm-send t
diff --git a/.local/bin/b-bar b/.local/bin/b-bar
new file mode 100755
index 0000000..e326673
--- /dev/null
+++ b/.local/bin/b-bar
@@ -0,0 +1,13 @@
+#!/bin/sh
+while true
+do
+ b0="/sys/class/power_supply/BAT0"
+ bat="$(cat $b0/capacity)"
+ # batl="$(cat $b0/capacity_level)"
+ vols="$(b-pavols)"
+ load="$(cat /proc/loadavg | cut -d' ' -f1)"
+ time="$(date +'%a, %d %b %Y %R %z')"
+ printf "%s%% | %s | %s | %s\n" \
+ "$bat" "$vols" "$load" "$time"
+ sleep 5
+done
diff --git a/.local/bin/pacify-pulseaudio b/.local/bin/b-pacify
index 18d6ee5..18d6ee5 100755
--- a/.local/bin/pacify-pulseaudio
+++ b/.local/bin/b-pacify
diff --git a/.local/bin/b-pavols b/.local/bin/b-pavols
new file mode 100755
index 0000000..76606e2
--- /dev/null
+++ b/.local/bin/b-pavols
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+# default sink (output)
+sink_volume="$(pactl get-sink-volume @DEFAULT_SINK@ | grep -Po '\d+(?=%)' | head -n1)"
+sink_mute="$(pactl get-sink-mute @DEFAULT_SINK@ | grep -o 'no\|yes')"
+# default source (input)
+source_volume="$(pactl get-source-volume @DEFAULT_SOURCE@ | grep -Po '\d+(?=%)' | head -n1)"
+source_mute="$(pactl get-source-mute @DEFAULT_SOURCE@ | grep -o 'no\|yes')"
+
+if [ "$sink_mute" = "no" ]; then
+ sink_mute='+'
+else
+ sink_mute='-'
+fi
+
+if [ "$source_mute" = "no" ]; then
+ source_mute='+'
+else
+ source_mute='-'
+fi
+
+printf "%s%s,%s%s\n" \
+ "$sink_volume" "$sink_mute" "$source_volume" "$source_mute"
diff --git a/.local/bin/my-bar b/.local/bin/my-bar
deleted file mode 100755
index 8a37d2f..0000000
--- a/.local/bin/my-bar
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/sh
-while true
-do
- b0="/sys/class/power_supply/BAT0"
- bat="$(cat $b0/capacity)"
- # batl="$(cat $b0/capacity_level)"
- sinkv="$(pactl get-sink-volume @DEFAULT_SINK@ | grep -Po '\d+(?=%)' | head -n1)"
- sinkm="$(pactl get-sink-mute @DEFAULT_SINK@ | grep -o 'no\|yes')"
- srcv="$(pactl get-source-volume @DEFAULT_SOURCE@ | grep -Po '\d+(?=%)' | head -n1)"
- srcm="$(pactl get-source-mute @DEFAULT_SOURCE@ | grep -o 'no\|yes')"
- [ "$sinkm" = "no" ] && sinkm='+' || sinkm='-'
- [ "$srcm" = "no" ] && srcm='+' || srcm='-'
- load="$(cat /proc/loadavg | cut -d' ' -f1)"
- time="$(date +'%a, %d %b %Y %R %z')"
- printf "%s%% | %s%s,%s%s | %s | %s\n" \
- "$bat" \
- "$sinkv" "$sinkm" "$srcv" "$srcm" \
- "$load" "$time"
- sleep 5
-done