From f257706816951b828272dfb3dfab2a95c7521d6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Thu, 7 Mar 2019 14:01:19 +0100 Subject: [PATCH] i3 bar: wifi --- dot/i3.nix | 8 ++- dot/i3blocks.nix | 183 ----------------------------------------------- 2 files changed, 6 insertions(+), 185 deletions(-) delete mode 100644 dot/i3blocks.nix diff --git a/dot/i3.nix b/dot/i3.nix index a0ca7d3..d53f687 100644 --- a/dot/i3.nix +++ b/dot/i3.nix @@ -8,6 +8,10 @@ let move-to-new-workspace = unstable.writers.writeDash "new-workspace" '' i3-msg move container to workspace $(($(i3-msg -t get_workspaces | tr , '\n' | grep '"num":' | cut -d : -f 2 | sort -rn | head -1) + 1)) ''; + wifi-interface = { + scardanelli = "wlp2s0"; + homeros = "wlp3s0"; + }.${config.networking.hostName}; in with import ../theme.nix; rec { fonts = [ "${uiFont.name} ${toString uiFont.size}" ]; @@ -68,13 +72,13 @@ rec { } order += "run_watch retiolum" - order += "wireless wlp3s0" + order += "wireless ${wifi-interface}" order += "battery all" order += "volume master" order += "load" order += "tztime local" - wireless wlp3s0 { + wireless ${wifi-interface} { format_up = "online" format_down = "offline" } diff --git a/dot/i3blocks.nix b/dot/i3blocks.nix deleted file mode 100644 index 0d0f744..0000000 --- a/dot/i3blocks.nix +++ /dev/null @@ -1,183 +0,0 @@ -{ pkgs }: -let - unstable = import {}; - spotify_info = unstable.writers.writeBash "spotify.info" '' - if $(pgrep spotify); then - STATUS=$(${pkgs.dbus}/bin/dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'PlaybackStatus'|egrep -A 1 "string"|cut -b 26-|cut -d '"' -f 1|egrep -v ^$) - - if [[ "$STATUS" == 'Playing' ]]; then - printf '\uf1bc ' - printf '\uf04b' - elif [[ "$STATUS" == 'Paused' ]]; then - printf '\uf1bc ' - printf '\uf04c' - elif [[ "$STATUS" == 'Stopped' ]]; then - printf '\uf1bc ' - printf '\uf04d' - else - exit 1 - fi - - printf ' ' - - METADATA=$(${pkgs.dbus}/bin/dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata') - ARTIST=$(echo "$METADATA" | egrep -A 2 "artist" | egrep -v "artist" | egrep -v "array" | cut -b 27- | cut -d '"' -f 1 | egrep -v ^$) - TITLE=$(echo "$METADATA" | egrep -A 1 "title" | egrep -v "title" | cut -b 44- | cut -d '"' -f 1 | egrep -v ^$) - - printf "%s \u2237 %s" "$ARTIST" "$TITLE" - fi - ''; - battery_info = unstable.writers.writeBash "battery.info" '' - BAT_DIR="/sys/class/power_supply/$BLOCK_INSTANCE/" - if [ -d "$BAT_DIR" ]; then - cd "$BAT_DIR" - else - exit 1 - fi - - if [ -e charge_now ] && [ -e charge_full ]; then - FULL_CHARGE=charge_full - CURR_CHARGE=charge_now - elif [ -e energy_now ] && [ -e energy_full ]; then - FULL_CHARGE=energy_full - CURR_CHARGE=energy_now - else - ls >&2 - exit 1 - fi - - status=$(cat status) - charge_f=$((100 * $(cat $CURR_CHARGE) / $(cat $FULL_CHARGE))) - - if [[ "$charge_f" -lt 20 ]]; then - printf '\uf244' - elif [[ "$charge_f" -lt 40 ]]; then - printf '\uf243' - elif [[ "$charge_f" -lt 60 ]]; then - printf '\uf242' - elif [[ "$charge_f" -lt 80 ]]; then - printf '\uf241' - else - printf '\uf240' - fi - - printf ' ' - - if [[ "$status" == 'Charging' ]]; then - printf '\uf106' - elif [[ "$status" == 'Discharging' ]]; then - printf '\uf107' - elif [[ "$status" == 'Full' ]]; then - printf '\uf0e7' - else - printf '[%s]' "$status" - fi - - printf ' ' - - if [[ "$status" != 'Full' ]]; then - rate_raw=$(($(cat voltage_now) * $(cat power_now))) - rate=$(bc <<< "scale=1; $rate_raw / 10^12") - printf '%s\u2009W, ' "$rate" - fi - - charge_d=$((100 * $(cat $CURR_CHARGE) / $(cat $FULL_CHARGE))) - printf '%s%%\n' "$charge_d" - - if [[ "$status" == 'Discharging' ]]; then - if [[ "$charge_d" -lt 10 ]]; then - printf '\n#E41C28' - elif [[ "$charge_d" -lt 20 ]]; then - printf '\n#EEBF13' - fi - fi - ''; - volume_info = unstable.writers.writeBash "volume.info" '' - if [[ "$BLOCK_BUTTON" == 1 ]]; then - ${pkgs.pamixer}/bin/pamixer -i 5 - elif [[ "$BLOCK_BUTTON" == 3 ]]; then - ${pkgs.pamixer}/bin/pamixer -d 5 - elif [[ "$BLOCK_BUTTON" == 2 ]]; then - ${pkgs.pamixer}/bin/pamixer -t - fi - - if $(${pkgs.pamixer}/bin/pamixer --get-mute); then - printf '\uf026 0%%\n\n#EEBF13' - else - volume=$(${pkgs.pamixer}/bin/pamixer --get-volume) - printf '\uf028 %s%%' "$volume" - fi - ''; - fancyDate = unstable.writers.writeC "fancy_date.c" {} '' - #include - #include - #include - - int main(void) { - time_t now = time(NULL); - struct tm *today = localtime(&now); - wchar_t roman_month = 0x2160 + today->tm_mon; - wprintf(L"%d\u2009%lc\u2009%d [%d|%d]\n", today->tm_mday, roman_month, 1900 + today->tm_year, today->tm_wday == 0 ? 7 : today->tm_wday, today->tm_yday/7 + 1); - return 0; - } - ''; -in with import ../theme.nix; '' - markup=pango - align=center - color=${white} - - [spotify] - command=${spotify_info} - interval=2 - - [separator] - - [volume] - command=${volume_info} - min_width= 100% - interval=once - signal=3 - - [separator] - - [cpu_usage] - command=cut -d' ' -f 1-3 < /proc/loadavg - label= - interval=2 - - [separator] - - [ram_usage] - command=free -h | grep "Mem" | awk '{print $3}' - label= - interval=2 - align=center - - [separator] - - [battery] - command=${battery_info} - interval=10 - instance=BAT1 - - [separator] - - [date] - command=${fancyDate} - interval=1 - label= - - [separator] - - [time] - command=date +'%H:%M' - interval=1 - label= - - [separator] - command=${pkgs.xkblayout-state}/bin/xkblayout-state print %s - label= - interval=2 - - [separator] -''