Use custom status bar in sway.
authorFrederik Vanrenterghem <frederik@vanrenterghem.biz>
Sun, 17 Nov 2019 12:06:30 +0000 (20:06 +0800)
committerFrederik Vanrenterghem <frederik@vanrenterghem.biz>
Sun, 17 Nov 2019 12:06:30 +0000 (20:06 +0800)
sway/.config/sway/config
sway/.config/sway/scripts/status.sh [new file with mode: 0755]

index 936d8baefb58f2a585f0fdf74b76acc2a7fe7b75..5c55f526adade478e4d80d2fd2ff63ea5d6873d3 100644 (file)
@@ -14,15 +14,16 @@ set $down j
 set $up k
 set $right l
 # Your preferred terminal emulator
-set $term urxvt
+set $term gnome-terminal
 # Your preferred application launcher
 # Note: it's recommended that you pass the final command to sway
-set $menu dmenu_path | dmenu | xargs swaymsg exec --
+#set $menu dmenu_path | dmenu | xargs swaymsg exec --
+set $menu j4-dmenu-desktop --dmenu='bemenu -i --nb "#3f3f3f" --nf "#dcdccc" --fn "pango:DejaVu Sans Mono 12"' --term='termite' | xargs swaymsg exec -- 
 
 ### Output configuration
 #
 # Default wallpaper (more resolutions are available in /usr/share/backgrounds/sway/)
-output * bg /usr/share/backgrounds/sway/Sway_Wallpaper_Blue_1920x1080.png fill
+output * bg /home/frederik/Pictures/sway_bg.jpg fill
 #
 # Example configuration:
 #
@@ -207,13 +208,16 @@ bar {
 
     # When the status_command prints a new line to stdout, swaybar updates.
     # The default just shows the current date and time.
-    status_command while date +'%Y-%m-%d %l:%M:%S %p'; do sleep 1; done
+    #status_command while date +'%Y-%m-%d %l:%M:%S %p'; do sleep 1; done
+    status_command while ~/.config/sway/scripts/status.sh; do sleep 1; done
 
     colors {
         statusline #ffffff
         background #323232
         inactive_workspace #32323200 #32323200 #5c5c5c
     }
+    #font "Terminus (TTF)"
+    font pango:DejaVu Sans Mono 10
 }
 
 include /etc/sway/config.d/*
diff --git a/sway/.config/sway/scripts/status.sh b/sway/.config/sway/scripts/status.sh
new file mode 100755 (executable)
index 0000000..002cb20
--- /dev/null
@@ -0,0 +1,81 @@
+# The Sway configuration file in ~/.config/sway/config calls this script.
+# You should see changes to the status bar after saving this script.
+# If not, do "killall swaybar" and $mod+Shift+c to reload the configuration.
+
+# Change this according to your device
+################
+# Variables
+################
+
+# Keyboard input name
+keyboard_input_name="1:1:AT_Translated_Set_2_keyboard"
+
+# Date and time
+date_and_week=$(date "+%Y/%m/%d (w%-V)")
+current_time=$(date "+%H:%M")
+
+#############
+# Commands
+#############
+
+# Battery or charger
+battery_charge=$(upower --show-info $(upower --enumerate | grep 'BAT') | egrep "percentage" | awk '{print $2}')
+battery_status=$(upower --show-info $(upower --enumerate | grep 'BAT') | egrep "state" | awk '{print $2}')
+
+# Audio and multimedia
+audio_volume=$(pamixer --sink `pactl list sinks short | grep RUNNING | awk '{print $1}'` --get-volume)
+audio_is_muted=$(pamixer --sink `pactl list sinks short | grep RUNNING | awk '{print $1}'` --get-mute)
+media_artist=$(playerctl metadata artist)
+media_song=$(playerctl metadata title)
+player_status=$(playerctl status)
+
+# Network
+network=$(ip route get 1.1.1.1 | grep -Po '(?<=dev\s)\w+' | cut -f1 -d ' ')
+# interface_easyname grabs the "old" interface name before systemd renamed it
+interface_easyname=$(dmesg | grep $network | grep renamed | awk 'NF>1{print $NF}')
+ping=$(ping -c 1 www.google.es | tail -1| awk '{print $4}' | cut -d '/' -f 2 | cut -d '.' -f 1)
+
+# Others
+language=$(swaymsg -r -t get_inputs | awk '/1:1:AT_Translated_Set_2_keyboard/;/xkb_active_layout_name/' | grep -A1 '\b1:1:AT_Translated_Set_2_keyboard\b' | grep "xkb_active_layout_name" | awk -F '"' '{print $4}')
+loadavg_5min=$(cat /proc/loadavg | awk -F ' ' '{print $2}')
+
+# Removed weather because we are requesting it too many times to have a proper
+# refresh on the bar
+#weather=$(curl -Ss 'https://wttr.in/Pontevedra?0&T&Q&format=1')
+
+if [ $battery_status = "discharging" ];
+then
+    battery_pluggedin='⚠'
+else
+    battery_pluggedin='⚡'
+fi
+
+if ! [ $network ]
+then
+   network_active="⛔"
+else
+   network_active="⇆"
+fi
+
+if [ $player_status = "Playing" ]
+then
+    song_status='▶'
+elif [ $player_status = "Paused" ]
+then
+    song_status='⏸'
+else
+    song_status='⏹'
+fi
+
+if [ $audio_is_muted = "true" ]
+then
+    audio_active='🔇'
+else
+    audio_active='🔊'
+fi
+
+# Emojis and characters for the status bar
+# 💎 💻 💡 🔌 ⚡ 📁 \|
+echo "🎧 $song_status $media_artist - $media_song | ⌨ $language | $network_active $interface_easyname ($ping ms) | 🏋 $loadavg_5min | $audio_active $audio_volume% | $battery_pluggedin $battery_charge | $date_and_week 🕘 $current_time"
+
+#echo $uptime_formatted ↑ $linux_version $battery_pluggedin $battery_charge 🕘 $date_formatted