diff options
author | NeodarZ <neodarz@neodarz.ovh> | 2016-09-18 02:11:28 +0200 |
---|---|---|
committer | NeodarZ <neodarz@neodarz.ovh> | 2016-09-18 02:11:28 +0200 |
commit | 9b6d154afb2b32f81dae99cc45392b4cace2a29d (patch) | |
tree | aadff76c1ae09353713378e20a3a24819730b499 /.i3-blocks | |
parent | d16075fbc32b9d8dde5b0638efc9cd9d241acdab (diff) | |
download | dotfiles-9b6d154afb2b32f81dae99cc45392b4cace2a29d.tar.xz dotfiles-9b6d154afb2b32f81dae99cc45392b4cace2a29d.zip |
Add more conf
Diffstat (limited to '')
37 files changed, 1324 insertions, 0 deletions
diff --git a/.i3-blocks/blocks/audio b/.i3-blocks/blocks/audio new file mode 100755 index 0000000..c401c68 --- /dev/null +++ b/.i3-blocks/blocks/audio @@ -0,0 +1,26 @@ +#!/bin/bash + +# Left click +if [[ "${BLOCK_BUTTON}" -eq 1 ]]; then + amixer -q sset Master 5%+ +# Middle click +elif [[ "${BLOCK_BUTTON}" -eq 2 ]]; then + amixer -q sset Master toggle +# Right click +elif [[ "${BLOCK_BUTTON}" -eq 3 ]]; then + amixer -q sset Master 5%- +fi + +statusLine=$(amixer get Master | tail -n 1) +status=$(echo "${statusLine}" | grep -wo "on") +volume=$(echo "${statusLine}" | awk -F ' ' '{print $5}' | tr -d '[]%') + +if [[ "${status}" == "on" ]]; then + echo "${volume}%" + echo "${volume}%" + echo "" +else + echo "off" + echo "off" + echo "" +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/bandwidth b/.i3-blocks/blocks/bandwidth new file mode 100755 index 0000000..f0b18cf --- /dev/null +++ b/.i3-blocks/blocks/bandwidth @@ -0,0 +1,96 @@ +#!/bin/bash +# Source: http://www.onlamp.com/pub/a/linux/2000/11/16/LinuxAdmin.html + +INSTANCE="${BLOCK_INSTANCE}" + +if [[ "${INSTANCE}" = "" ]]; then + INSTANCE="wlp3s0;both" +fi + +DISPLAY=$(echo "${INSTANCE}" | awk -F ';' '{print $2}') +INSTANCE=$(echo "${INSTANCE}" | awk -F ';' '{print $1}') + +if [[ "${DISPLAY}" = "" ]]; then + DISPLAY="both" +fi + +ONE_KB=1024 +ONE_MB=$(echo "${ONE_KB}*1024" | bc -l) +TEN_MB=$(echo "${ONE_MB}*10" | bc -l) +OHD_MB=$(echo "${TEN_MB}*10" | bc -l) + +URGENT_VALUE="${ONE_MB}" + +PREV_IN=0 +PREV_OUT=0 + +PREV_FILE="/tmp/.bandwidth" + +if [[ -f "${PREV_FILE}" ]]; then + PREV_CONT=$(cat "${PREV_FILE}") + PREV_IN=$(echo "${PREV_CONT}" | head -n 1) + PREV_OUT=$(echo "${PREV_CONT}" | tail -n 1) +fi + +BANDWIDTH=$(grep "${INSTANCE}" /proc/net/dev | awk -F: '{print $2}' | awk '{print $1" "$9}') + +if [[ "${BANDWIDTH}" = "" ]]; then + exit +fi + +BYTES_IN=$(echo "${BANDWIDTH}" | awk -F ' ' '{print $1}') +BYTES_OUT=$(echo "${BANDWIDTH}" | awk -F ' ' '{print $2}') + +function FormatNumber() { + if [[ "${1}" -ge "${OHD_MB}" ]]; then + echo $(echo "scale=0;${1}/${ONE_MB}" | bc -l)"mb" + elif [[ "${1}" -ge "${TEN_MB}" ]]; then + echo $(echo "scale=1;${1}/${ONE_MB}" | bc -l)"mb" + elif [[ "${1}" -ge "${ONE_MB}" ]]; then + echo $(echo "scale=2;${1}/${ONE_MB}" | bc -l)"mb" + elif [[ "${1}" -ge "${ONE_KB}" ]]; then + echo $(echo "scale=0;${1}/${ONE_KB}" | bc -l)"kb" + else + echo "${1}""b" + fi +} + +if [[ "${PREV_IN}" != "" ]] && [[ "${PREV_OUT}" != "" ]]; then + # Calculate the CPU usage since we last checked. + DIFF_IN=$(echo "scale=0;${BYTES_IN} - ${PREV_IN}" | bc -l) + DIFF_OUT=$(echo "scale=0;${BYTES_OUT} - ${PREV_OUT}" | bc -l) + DIFF_TOTAL=0 + + USAGE_IN=$(FormatNumber "${DIFF_IN}") + USAGE_OUT=$(FormatNumber "${DIFF_OUT}") + + if [[ "${DISPLAY}" = "both" ]]; then + echo "${USAGE_IN} : ${USAGE_OUT}" + echo "${USAGE_IN} : ${USAGE_OUT}" + echo "" + DIFF_TOTAL=$((DIFF_TOTAL+DIFF_IN)) + DIFF_TOTAL=$((DIFF_TOTAL+DIFF_OUT)) + elif [[ "${DISPLAY}" = "in" ]]; then + echo "${USAGE_IN}" + echo "${USAGE_IN}" + echo "" + DIFF_TOTAL=$((DIFF_TOTAL+DIFF_IN)) + elif [[ "${DISPLAY}" = "out" ]]; then + echo "${USAGE_OUT}" + echo "${USAGE_OUT}" + echo "" + DIFF_TOTAL=$((DIFF_TOTAL+DIFF_OUT)) + fi +else + echo "?" + echo "?" + echo "" +fi + +# Remember the total and idle CPU times for the next check. +echo "${BYTES_IN}" > "${PREV_FILE}" +echo "${BYTES_OUT}" >> "${PREV_FILE}" + +if [[ "${DIFF_TOTAL}" -ge "${URGENT_VALUE}" ]]; then + exit 33 +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/battery b/.i3-blocks/blocks/battery new file mode 100755 index 0000000..3058f36 --- /dev/null +++ b/.i3-blocks/blocks/battery @@ -0,0 +1,26 @@ +#!/bin/bash + +BATTERY=0 +BATTERY_INFO=$(acpi -b | grep "Battery ${BATTERY}") +BATTERY_STATE=$(echo "${BATTERY_INFO}" | grep -wo "Full\|Charging\|Discharging") +BATTERY_POWER=$(echo "${BATTERY_INFO}" | grep -o '[0-9]\+%' | tr -d '%') + +URGENT_VALUE=10 + +if [[ "${BATTERY_STATE}" = "Charging" ]]; then + echo "${BATTERY_POWER}%+" + echo "${BATTERY_POWER}%+" + echo "" +elif [[ "${BATTERY_STATE}" = "Discharging" ]]; then + echo "${BATTERY_POWER}%-" + echo "${BATTERY_POWER}%-" + echo "" +else + echo "${BATTERY_POWER}%" + echo "${BATTERY_POWER}%" + echo "" +fi + +if [[ "${BATTERY_POWER}" -le "${URGENT_VALUE}" ]]; then + exit 33 +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/bluetooth b/.i3-blocks/blocks/bluetooth new file mode 100755 index 0000000..c9673a5 --- /dev/null +++ b/.i3-blocks/blocks/bluetooth @@ -0,0 +1,20 @@ +#!/bin/bash + +# Left click +if [[ "${BLOCK_BUTTON}" -eq 1 ]]; then + sudo bluetooth on +# Middle click +elif [[ "${BLOCK_BUTTON}" -eq 2 ]]; then + sudo bluetooth toggle +# Right click +elif [[ "${BLOCK_BUTTON}" -eq 3 ]]; then + sudo bluetooth off +fi + +STATUS=$(bluetooth | grep -wo 'on') + +if [[ "${STATUS}" = "on" ]]; then + echo "on" + echo "on" + echo "" +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/brightness b/.i3-blocks/blocks/brightness new file mode 100755 index 0000000..f6294e4 --- /dev/null +++ b/.i3-blocks/blocks/brightness @@ -0,0 +1,57 @@ +#!/bin/bash + +# One of the following: xrandr, xbacklight, kernel +METHOD="xbacklight" + +# Left click +if [[ "${BLOCK_BUTTON}" -eq 1 ]]; then + xbacklight -inc 5 +# Right click +elif [[ "${BLOCK_BUTTON}" -eq 3 ]]; then + xbacklight -dec 5 +fi + +URGENT_VALUE=10 + +if [[ "${METHOD}" = "xrandr" ]]; then + device="${BLOCK_INSTANCE:-primary}" + xrandrOutput=$(xrandr --verbose) + + if [[ "${device}" = "primary" ]]; then + device=$(echo "${xrandrOutput}" | grep 'primary' | head -n 1 | awk -F ' ' '{print $1}') + fi + + curBrightness=$(echo "${xrandrOutput}" | grep "${device}" -A 5 | grep -i "Brightness" | awk -F ':' '{print $2}') +elif [[ "${METHOD}" = "kernel" ]]; then + device="${BLOCK_INSTANCE:-intel_backlight}" + maxBrightness=$(cat /sys/class/backlight/${device}/max_brightness) + curBrightness=$(cat /sys/class/backlight/${device}/brightness) +elif [[ "${METHOD}" = "xbacklight" ]]; then + curBrightness=$(xbacklight -get) +fi + +if [[ "${curBrightness}" -le 0 ]]; then + exit +fi + +if [[ "${METHOD}" = "xrandr" ]]; then + percent=$(echo "scale=0;${curBrightness} * 100" | bc -l) +elif [[ "${METHOD}" = "kernel" ]]; then + percent=$(echo "scale=0;${curBrightness} / ${maxBrightness} * 100" | bc -l) +elif [[ "${METHOD}" = "xbacklight" ]]; then + percent=$(echo "scale=0;${curBrightness}" | bc -l) +fi + +percent=${percent%.*} + +if [[ "${percent}" -le 0 ]]; then + exit +fi + +echo "${percent}%" +echo "${percent}%" +echo "" + +if [[ "${percent}" -le "${URGENT_VALUE}" ]]; then + exit 33 +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/cmus b/.i3-blocks/blocks/cmus new file mode 100755 index 0000000..f4d15b3 --- /dev/null +++ b/.i3-blocks/blocks/cmus @@ -0,0 +1,20 @@ +#!/bin/bash + +INFO_CMUS=$(cmus-remote -Q 2>/dev/null) +if [[ $? -eq 0 ]]; then + INFO_TITLE=$(echo "${INFO_CMUS}" | sed -n -e 's/^.*title//p' | head -n 1) + INFO_ALBUM=$(echo "${INFO_CMUS}" | sed -n -e 's/^.*album//p' | head -n 1) + INFO_ARTIST=$(echo "${INFO_CMUS}" | sed -n -e 's/^.*artist//p' | head -n 1) +else + exit +fi + +if [[ "${INFO_ARTIST}" ]] && [[ "${INFO_TITLE}" ]]; then + OUT_TEXT=$(echo "${INFO_ARTIST} - ${INFO_TITLE}" | xargs) +elif [[ "${INFO_TITLE}" ]]; then + OUT_TEXT=$(echo "${INFO_TITLE}" | xargs) +fi + +echo "${OUT_TEXT}" +echo "${OUT_TEXT}" +exit
\ No newline at end of file diff --git a/.i3-blocks/blocks/countdown b/.i3-blocks/blocks/countdown new file mode 100755 index 0000000..311a3b7 --- /dev/null +++ b/.i3-blocks/blocks/countdown @@ -0,0 +1,36 @@ +#!/bin/bash + +END_DATE="${BLOCK_INSTANCE}" + +URGENT_VALUE=86400 + +if [[ "${END_DATE}" = "" ]]; then + END_DATE=$(date --date "next Friday" "+%m/%d/%Y %H:%M:%S") +fi + +END_DATE=$(date --date="${END_DATE}" '+%s') +CUR_DATE=$(date "+%s") +DIFF_DATE=$((END_DATE - CUR_DATE)) +DIFF="" + +if [[ "${DIFF_DATE}" -le 0 ]]; then + echo "${END_DATE}" + echo "${END_DATE}" + echo "" + exit 33 +fi + +if [[ "${DIFF_DATE}" -ge 86400 ]]; then + DIFF="[$((DIFF_DATE / 86400))] " + #DIFF_DATE=$((DIFF_DATE % 86400)) +fi + +DIFF+=$(date -u -d "@${DIFF_DATE}" +"%H:%M:%S") + +echo "${DIFF}" +echo "${DIFF}" +echo "" + +if [[ "${DIFF_DATE}" -le "${URGENT_VALUE}" ]]; then + exit 33 +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/cpu b/.i3-blocks/blocks/cpu new file mode 100755 index 0000000..2cb27ad --- /dev/null +++ b/.i3-blocks/blocks/cpu @@ -0,0 +1,48 @@ +#!/bin/bash +# Source: http://askubuntu.com/a/450136 + +URGENT_VALUE=90 + +PREV_TOTAL=0 +PREV_IDLE=0 + +cpuFile="/tmp/.cpu" + +if [[ -f "${cpuFile}" ]]; then + fileCont=$(cat "${cpuFile}") + PREV_TOTAL=$(echo "${fileCont}" | head -n 1) + PREV_IDLE=$(echo "${fileCont}" | tail -n 1) +fi + +CPU=(`cat /proc/stat | grep '^cpu '`) # Get the total CPU statistics. +unset CPU[0] # Discard the "cpu" prefix. +IDLE=${CPU[4]} # Get the idle CPU time. + +# Calculate the total CPU time. +TOTAL=0 + +for VALUE in "${CPU[@]:0:4}"; do + let "TOTAL=$TOTAL+$VALUE" +done + +if [[ "${PREV_TOTAL}" != "" ]] && [[ "${PREV_IDLE}" != "" ]]; then + # Calculate the CPU usage since we last checked. + let "DIFF_IDLE=$IDLE-$PREV_IDLE" + let "DIFF_TOTAL=$TOTAL-$PREV_TOTAL" + let "DIFF_USAGE=(1000*($DIFF_TOTAL-$DIFF_IDLE)/$DIFF_TOTAL+5)/10" + echo "${DIFF_USAGE}%" + echo "${DIFF_USAGE}%" + echo "" +else + echo "?" + echo "?" + echo "" +fi + +# Remember the total and idle CPU times for the next check. +echo "${TOTAL}" > "${cpuFile}" +echo "${IDLE}" >> "${cpuFile}" + +if [[ "${DIFF_USAGE}" -gt 0 ]] && [[ "${DIFF_USAGE}" -gt "${URGENT_VALUE}" ]]; then + exit 33 +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/datetime b/.i3-blocks/blocks/datetime new file mode 100755 index 0000000..178073f --- /dev/null +++ b/.i3-blocks/blocks/datetime @@ -0,0 +1,8 @@ +#!/bin/bash + +FORMAT="${BLOCK_INSTANCE:-%H:%M}" +DATETIME=$(date "+${FORMAT}") + +echo "${DATETIME}" +echo "${DATETIME}" +echo ""
\ No newline at end of file diff --git a/.i3-blocks/blocks/display b/.i3-blocks/blocks/display new file mode 100755 index 0000000..9071900 --- /dev/null +++ b/.i3-blocks/blocks/display @@ -0,0 +1,68 @@ +#!/bin/bash + +xrandrOut=$(xrandr) + +hdmiName=$(echo "${xrandrOut}" | grep -i 'HDMI' | awk '{print $1}') +vgaName=$(echo "${xrandrOut}" | grep -i 'VGA' | awk '{print $1}') +edpName=$(echo "${xrandrOut}" | grep -i 'EDP' | awk '{print $1}') + +activeDisplays=$(echo "${xrandrOut}" | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/" | tr -s '\n' ' ') +displayFile='/tmp/.displays' + +if [[ -f "${displayFile}" ]]; then + oldDisplays=$(cat "${displayFile}") +else + oldDisplays="" +fi + +if [[ "${oldDisplays}" != "${activeDisplays}" ]]; then + change="yes" +else + change="no" +fi + +# External, HDMI + VGA +if [[ "$activeDisplays" =~ "${hdmiName}" && "$activeDisplays" =~ "${vgaName}" ]]; then + if [[ "${change}" = "yes" ]]; then + $(xrandr --output "${edpName}" --off) + $(xrandr --output "${vgaName}" --auto) + $(xrandr --output "${hdmiName}" --primary --auto) + fi + echo "VGA1 & HDMI" + echo "VGA1 & HDMI" + echo "" +# External, HDMI +elif [[ "$activeDisplays" =~ "${hdmiName}" ]]; then + if [[ "${change}" = "yes" ]]; then + $(xrandr --output "${edpName}" --off) + $(xrandr --output "${vgaName}" --off) + $(xrandr --output "${hdmiName}" --primary --auto) + fi + echo "HDMI" + echo "HDMI" + echo "" +# External, VGA +elif [[ "$activeDisplays" =~ "${vgaName}" ]]; then + if [[ "${change}" = "yes" ]]; then + $(xrandr --output "${edpName}" --off) + $(xrandr --output "${vgaName}" --primary --auto) + $(xrandr --output "${hdmiName}" --off) + fi + echo "VGA" + echo "VGA" + echo +# Only one internal +elif [[ "$activeDisplays" =~ "${edpName}" ]]; then + if [[ "${change}" = "yes" ]]; then + $(xrandr --output "${edpName}" --primary --auto) + $(xrandr --output "${vgaName}" --off) + $(xrandr --output "${hdmiName}" --off) + fi + echo "eDP" + echo "eDP" + echo "" +fi + +if [[ "${change}" = "yes" ]]; then + echo "${activeDisplays}" > "${displayFile}" +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/feed b/.i3-blocks/blocks/feed new file mode 100755 index 0000000..0030939 --- /dev/null +++ b/.i3-blocks/blocks/feed @@ -0,0 +1,31 @@ +#!/bin/bash + +# WARNING: This has a LIMIT of 32 characters for now! +# If your URL is longer you should use an URL shortener +# Caused by https://github.com/vivien/i3blocks/blob/01a4f4a9ca1e3d0b3c95d1d62000ad8506bdff1a/include/block.h#L50 +# Example: https://goo.gl/ +FEED_URL="${BLOCK_INSTANCE:-https://www.archlinux.org/feeds/news/}" + +if [[ "${FEED_URL}" = "" ]]; then + exit +fi + +# Follows redirects! +FEED_CONTENT=$(curl ${FEED_URL} -s -L) +FEED_TITLE=$(echo "${FEED_CONTENT}" | grep -v "xmlns:atom" | grep -o '<title>.*</title>' | head -n 1 | sed 's/\(<title>\|<\/title>\)//g') +FEED_LINK=$(echo "${FEED_CONTENT}" | grep -v "xmlns:atom" | grep -o '<link>.*</link>' | head -n 1 | sed 's/\(<link>\|<\/link>\)//g') + +if [[ "${FEED_TITLE}" = *404* ]]; then + echo "${FEED_URL}" + echo "${FEED_URL}" + echo "" + exit 33 +fi + +if [[ "${BLOCK_BUTTON}" -eq 1 ]]; then + xdg-open "${FEED_LINK}" +fi + +echo "${FEED_TITLE}" +echo "${FEED_TITLE}" +echo ""
\ No newline at end of file diff --git a/.i3-blocks/blocks/firewall b/.i3-blocks/blocks/firewall new file mode 100755 index 0000000..6fe26f6 --- /dev/null +++ b/.i3-blocks/blocks/firewall @@ -0,0 +1,28 @@ +#!/bin/bash + +# Left click +if [[ "${BLOCK_BUTTON}" -eq 1 ]]; then + sudo ufw enable +# Middle click +elif [[ "${BLOCK_BUTTON}" -eq 2 ]]; then + sudo ufw reload +# Right click +elif [[ "${BLOCK_BUTTON}" -eq 3 ]]; then + sudo ufw disable +fi + +status=$(sudo ufw status 2>/dev/null) + +if [[ $? -gt 0 ]]; then + exit +fi + +if [[ "${status}" != *inactive* ]]; then + echo "on" + echo "on" + echo "" +else + echo "off" + echo "off" + echo "" +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/ip-address b/.i3-blocks/blocks/ip-address new file mode 100755 index 0000000..d91ab56 --- /dev/null +++ b/.i3-blocks/blocks/ip-address @@ -0,0 +1,9 @@ +#!/bin/bash + +IP_ADDRESS=$(ip route get 1 | awk '{print $NF;exit}') + +if [[ "${IP_ADDRESS}" != "" ]]; then + echo "${IP_ADDRESS}" + echo "${IP_ADDRESS}" + echo "" +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/keymap b/.i3-blocks/blocks/keymap new file mode 100755 index 0000000..f25ee98 --- /dev/null +++ b/.i3-blocks/blocks/keymap @@ -0,0 +1,27 @@ +#!/bin/bash + +KEYMAP_DIRECTORY='/usr/share/kbd/keymaps' + +# Aprrently localectl status does not update on keymap change. However, setxkbmap does. +XKB_OUTPUT=$(setxkbmap -query) +VC_KEYMAP=$(echo "${XKB_OUTPUT}" | grep "layout" | awk -F ':' '{print $2}' | tr -d ' ') +VC_VARIANT=$(echo "${XKB_OUTPUT}" | grep "variant" | awk -F ':' '{print $2}' | tr -d ' ') + +# Keymap has not been specific, so it's not configured properly +if [[ "${VC_KEYMAP}" == "" ]]; then + exit 1 +fi + +KEYMAP_FILE="${VC_KEYMAP}*" + +if [[ "${VC_VARIANT}" != "" ]]; then + KEYMAP_FILE="${KEYMAP_FILE}${VC_VARIANT}*" +fi + +KEYMAP_NAME=$(basename $(dirname $(find ${KEYMAP_DIRECTORY} -name "${KEYMAP_FILE}"))) + +if [[ "${KEYMAP_NAME}" ]]; then + echo "${KEYMAP_NAME}" + echo "${KEYMAP_NAME}" + echo "" +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/keystate b/.i3-blocks/blocks/keystate new file mode 100755 index 0000000..e1543d7 --- /dev/null +++ b/.i3-blocks/blocks/keystate @@ -0,0 +1,25 @@ +#!/bin/bash + +TYPE="${BLOCK_INSTANCE:-caps}" + +lockLine=$(xset -q | grep "Num Lock") + +capsLock=$(echo "${lockLine}" | awk -F ' ' '{print $4}') +numLock=$(echo "${lockLine}" | awk -F ' ' '{print $8}') +scrollLock=$(echo "${lockLine}" | awk -F ' ' '{print $12}') + +if [[ "${TYPE}" == "caps" ]]; then + checkLock="${capsLock}" +elif [[ "${TYPE}" == "num" ]]; then + checkLock="${numLock}" +elif [[ "${TYPE}" == "scroll" ]]; then + checkLock="${scrollLock}" +else + exit +fi + +if [[ "${checkLock}" == "on" ]]; then + echo "on" + echo "on" + echo "" +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/launcher b/.i3-blocks/blocks/launcher new file mode 100755 index 0000000..1e39432 --- /dev/null +++ b/.i3-blocks/blocks/launcher @@ -0,0 +1,26 @@ +#!/bin/bash + +CONFIG_FILE="${BLOCK_INSTANCE:-~/.config/i3/config}" +CONFIG_FILE=${CONFIG_FILE/\~/$HOME} + +LAUNCH_CMD=$(cat "${CONFIG_FILE}" | grep -v "^#" | grep -wi 'rofi\|dmenu' | awk -F 'exec ' '{print $2}') +LAUNCH_NAME=$(echo "${LAUNCH_CMD}" | awk -F ' ' '{print $1}') + +VARIABLES=$(cat "${CONFIG_FILE}" | grep -E 'set\ \$' | awk -F ' ' '{$1 = "";print $0}') + +while read varPair; do + varName=$(echo "${varPair}" | awk -F ' ' '{print $1}') + varValue=$(echo "${varPair}" | awk -F ' ' '{print $2}') + #echo "Replacing ${varName} with ${varValue}" + LAUNCH_CMD=$(echo ${LAUNCH_CMD} | sed "s|$varName|$varValue|g") +done <<< "$(echo -e "$VARIABLES")" + +#echo "${LAUNCH_CMD}" && exit + +echo "${LAUNCH_NAME}" +echo "${LAUNCH_NAME}" +echo "" + +if [[ "${BLOCK_BUTTON}" -gt 0 ]]; then + eval ${LAUNCH_CMD} & +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/load b/.i3-blocks/blocks/load new file mode 100755 index 0000000..448876f --- /dev/null +++ b/.i3-blocks/blocks/load @@ -0,0 +1,19 @@ +#!/bin/bash + +INSTANCE="${BLOCK_INSTANCE:-1}" + +URGENT_VALUE=90 + +LOAD=$(cat /proc/loadavg | awk -F ' ' '{print $'"${INSTANCE}"'}') +if [[ "${LOAD}" != "" ]]; then + LOAD_PERC=$(echo "scale=0; ${LOAD} * 100" | bc -l) + LOAD_PERC=${LOAD_PERC%.*} + + echo "${LOAD}" + echo "${LOAD}" + echo "" + + if [[ "${LOAD_PERC}" -ge "${URGENT_VALUE}" ]]; then + exit 33 + fi +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/locale b/.i3-blocks/blocks/locale new file mode 100755 index 0000000..e517c44 --- /dev/null +++ b/.i3-blocks/blocks/locale @@ -0,0 +1,10 @@ +#!/bin/bash + +LOCALE_INFO=$(localectl) +LOCALE_NAME=$(echo "${LOCALE_INFO}" | grep "System Locale" | awk -F '=' '{print $2}' | cut -c 1-2) + +if [[ "${LOCALE_NAME}" ]]; then + echo "${LOCALE_NAME}" + echo "${LOCALE_NAME}" + echo "" +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/mail b/.i3-blocks/blocks/mail new file mode 100755 index 0000000..66b1d0a --- /dev/null +++ b/.i3-blocks/blocks/mail @@ -0,0 +1,59 @@ +#!/bin/bash + +# Requires https://www.google.com/settings/security/lesssecureapps for gmail. + +CONFIG_FILE="${BLOCK_INSTANCE}" +CONFIG_FILE=${CONFIG_FILE/\~/$HOME} + +# Config file needs the following settings: +#MAIL_SERVER="imap.domain.tld:993" +#MAIL_USER="user@domain.tld" +#MAIL_PASSWORD="secret" +#MAIL_FOLDER="INBOX" + +if [[ ! -f "${CONFIG_FILE}" ]]; then + echo "${CONFIG_FILE}" + exit 33 +fi + +source "${CONFIG_FILE}" + +MAIN_DOMAIN=$(expr match "${MAIL_SERVER}" '.*\.\(.*\..*\)' | awk -F ':' '{print $1}') + +# Add https so xdg knows that it's a website +if [[ "${MAIN_DOMAIN}" != http* ]]; then + MAIN_DOMAIN="https://${MAIN_DOMAIN}" +fi + +# Left click +if [[ "${BLOCK_BUTTON}" -eq 1 ]]; then + xdg-open "${MAIN_DOMAIN}" +fi + +MAIL_FILE="/tmp/.mail" +URGENT_VALUE="100" + +GET_UNREAD=$(cat<<EOF +? LOGIN "${MAIL_USER}" "${MAIL_PASSWORD}" +? STATUS "${MAIL_FOLDER}" (unseen) +? LOGOUT +EOF +) + +echo "${GET_UNREAD}" | openssl s_client -connect "${MAIL_SERVER}" -crlf -ign_eof > "${MAIL_FILE}" 2>/dev/null +UNREAD_COUNT=$(cat "${MAIL_FILE}" | grep -i "UNSEEN" | grep -oE "[0-9]*" | head -n 1) + +# For security reasons +rm "${MAIL_FILE}" + +if [[ "${UNREAD_COUNT}" = "" ]]; then + exit +fi + +echo "${UNREAD_COUNT}" +echo "${UNREAD_COUNT}" +echo "" + +if [[ "${UNREAD_COUNT}" -ge URGENT_VALUE ]]; then + exit 33 +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/memory b/.i3-blocks/blocks/memory new file mode 100755 index 0000000..866e7c3 --- /dev/null +++ b/.i3-blocks/blocks/memory @@ -0,0 +1,69 @@ +#!/bin/bash + +# First argument is source (mem/swap), second is output value +# Check /proc/meminfo for possible instances +INSTANCE="${BLOCK_INSTANCE:-mem;free}" + +SOURCE=$(echo "${INSTANCE}" | awk -F ';' '{print $1}') +DISPLAY=$(echo "${INSTANCE}" | awk -F ';' '{print $2}') + +if [[ "${SOURCE}" = "mem" ]]; then + URGENT_VALUE=90 +elif [[ "${SOURCE}" = "swap" ]]; then + URGENT_VALUE=50 +fi + +if [[ "${DISPLAY}" = "" ]]; then + DISPLAY="free" +fi + +ONE_KB=1024 +ONE_MB=$(echo "${ONE_KB}*1024" | bc -l) +ONE_GB=$(echo "${ONE_MB}*1024" | bc -l) +ONE_TB=$(echo "${ONE_GB}*1024" | bc -l) + +# Grep the value and remove KB so we can calculate with it later +#MEMINFO=$(cat /proc/meminfo | grep "${INSTANCE}" | awk -F ':' '{print $2}' | tr -d ' kB') +MEMORY_INFOS=$(cat /proc/meminfo) +SOURCE_TOTAL=$(echo "${MEMORY_INFOS}" | grep -i "${SOURCE}total" | awk -F ':' '{print $2}' | tr -d ' kB') + +if [[ "${SOURCE_TOTAL}" -le 0 ]]; then + exit +fi + +SOURCE_FREE=$(echo "${MEMORY_INFOS}" | grep -i "${SOURCE}available" | awk -F ':' '{print $2}' | tr -d ' kB') +SOURCE_USED=$(echo "scale=0; ${SOURCE_TOTAL}-${SOURCE_FREE}" | bc -l) +SOURCE_PERC=$(echo "scale=0; (${SOURCE_USED}*100)/${SOURCE_TOTAL}" | bc -l) + +if [[ "${DISPLAY}" = "free" ]]; then + MEMINFO="${SOURCE_FREE}" +elif [[ "${DISPLAY}" = "used" ]]; then + MEMINFO="${SOURCE_USED}" +elif [[ "${DISPLAY}" = "total" ]]; then + MEMINFO="${SOURCE_TOTAL}" +elif [[ "${DISPLAY}" = "perc" ]]; then + MEMINFO="${SOURCE_PERC}%" +fi + +if [[ "${DISPLAY}" != "perc" ]]; then + # Convert KB meminfo to bytes + MEMINFO=$(echo "${MEMINFO}*${ONE_KB}" | bc -l) + + if [[ "${MEMINFO}" -ge "${ONE_TB}" ]]; then + MEMINFO=$(echo "scale=3;${MEMINFO}/${ONE_TB}" | bc -l)"tb" + elif [[ "${MEMINFO}" -ge "${ONE_GB}" ]]; then + MEMINFO=$(echo "scale=2;${MEMINFO}/${ONE_GB}" | bc -l)"gb" + elif [[ "${MEMINFO}" -ge "${ONE_MB}" ]]; then + MEMINFO=$(echo "scale=1;${MEMINFO}/${ONE_MB}" | bc -l)"mb" + else + MEMINFO=$(echo "scale=0;${MEMINFO}/${ONE_KB}" | bc -l)"kb" + fi +fi + +echo "${MEMINFO}" +echo "${MEMINFO}" +echo "" + +if [[ "${SOURCE_PERC}" -gt "${URGENT_VALUE}" ]]; then + exit 33 +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/microphone b/.i3-blocks/blocks/microphone new file mode 100755 index 0000000..76ff3f9 --- /dev/null +++ b/.i3-blocks/blocks/microphone @@ -0,0 +1,26 @@ +#!/bin/bash + +# Left click +if [[ "${BLOCK_BUTTON}" -eq 1 ]]; then + amixer -q sset Capture 5%+ +# Middle click +elif [[ "${BLOCK_BUTTON}" -eq 2 ]]; then + amixer -q sset Capture toggle +# Right click +elif [[ "${BLOCK_BUTTON}" -eq 3 ]]; then + amixer -q sset Capture 5%- +fi + +statusLine=$(amixer get Capture | tail -n 1) +status=$(echo "${statusLine}" | grep -wo "on") +volume=$(echo "${statusLine}" | awk -F ' ' '{print $5}' | tr -d '[]%') + +if [[ "${status}" == "on" ]]; then + echo "${volume}%" + echo "${volume}%" + echo "" +else + echo "off" + echo "off" + echo "" +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/network b/.i3-blocks/blocks/network new file mode 100755 index 0000000..cb06e87 --- /dev/null +++ b/.i3-blocks/blocks/network @@ -0,0 +1,23 @@ +#!/bin/bash + +device="${BLOCK_INSTANCE:-wlan0}" +status=$(cat /sys/class/net/${device}/operstate) + +URGENT_VALUE=20 + +if [[ "${status}" == "up" ]]; then + if [[ -d "/sys/class/net/${device}/wireless" ]]; then + quality=$(grep ${device} /proc/net/wireless | awk '{ print int($3 * 100 / 70) }') + echo "${quality}%" + echo "${quality}%" + echo "" + + if [[ "${quality}" -le "${URGENT_VALUE}" ]]; then + exit 33 + fi + else + echo "on" + echo "on" + echo "" + fi +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/notifier b/.i3-blocks/blocks/notifier new file mode 100755 index 0000000..35c94f1 --- /dev/null +++ b/.i3-blocks/blocks/notifier @@ -0,0 +1,185 @@ +#!/bin/bash +# IMPORTANT: +# To make this block work, you have to edit your block-command. +# It should point to this file. For best performance, only use it on blocks +# you want to monitor. +# +# Example: +# command=~/.i3-blocks/blocks/notifier $BLOCK_NAME + +BLOCK_NAME="${1}" + +if [[ "${BLOCK_NAME}" == "" ]] || [[ "${BLOCK_NAME}" == "notifier" ]]; then + exit 1 +fi + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +BLOCK_PATH="${SCRIPT_DIR}/${BLOCK_NAME}" + +if [[ ! -f "${BLOCK_PATH}" ]]; then + exit 1 +fi + +BLOCK_OUT=$(bash "${BLOCK_PATH}") +BLOCK_URGENT=$? + +# Nothing to display. +if [[ "${BLOCK_OUT}" == "" ]]; then + exit "${BLOCK_URGENT}" +fi + +NOTIFY=0 + +NOTIFY_CHANGES="weather display" +NOTIFY_ALWAYS="" +NOTIFY_NEVER="launcher playerctl scroll" + +if [[ "${NOTIFY_NEVER}" != *${BLOCK_NAME}* ]]; then + BLOCK_UCFIRST=$(echo "${BLOCK_NAME}" | head -c 1 | tr [a-z] [A-Z]; echo "${BLOCK_NAME}" | tail -c +2) + + CHECK_SUM=$(echo "${BLOCK_NAME}-${BLOCK_INSTANCE}" | md5sum | awk '{print $1}') + CACHE_FILE="/tmp/.notify-cache-${CHECK_SUM}" + + BLOCK_DESC=$(echo "${BLOCK_OUT}" | head -n 1) + BLOCK_VALUE=$(echo "${BLOCK_OUT}" | tail -n 1) + BLOCK_ICON="" + + if [[ "${NOTIFY_ALWAYS}" == *${BLOCK_NAME}* ]]; then + NOTIFY=1 + elif [[ "${BLOCK_URGENT}" -gt 0 ]]; then + NOTIFY=1 + fi + + VALUE_CHANGED=0 + HAS_CACHEFILE=0 + if [[ -f "${CACHE_FILE}" ]]; then + HAS_CACHEFILE=1 + CACHED_VALUE=$(cat "${CACHE_FILE}") + #MODIFIED_TIME=$(stat -c '%Y' "${CACHE_FILE}") + #CURRENT_TIME=$(date +%s) + #ELAPSED_TIME=$((MODIFIED_TIME - CURRENT_TIME)) + if [[ "${BLOCK_VALUE}" != "${CACHED_VALUE}" ]]; then + VALUE_CHANGED=1 + if [[ "${NOTIFY_CHANGES}" == *${BLOCK_NAME}* ]]; then + NOTIFY=1 + fi + fi + elif [[ "${NOTIFY_CHANGES}" == *${BLOCK_NAME}* ]]; then + NOTIFY=1 + fi + + if [[ "${NOTIFY}" -eq 1 ]]; then + if [[ "${BLOCK_NAME}" == "audio" ]]; then + BLOCK_MESSAGE="Audio level changed to ${BLOCK_VALUE}." + elif [[ "${BLOCK_NAME}" == "bandwidth" ]]; then + BLOCK_MESSAGE="Traffic went to ${BLOCK_VALUE}." + elif [[ "${BLOCK_NAME}" == "battery" ]]; then + BLOCK_MESSAGE="Energy changed to ${BLOCK_VALUE}." + elif [[ "${BLOCK_NAME}" == "countdown" ]]; then + BLOCK_MESSAGE="Remaining time is now ${BLOCK_VALUE}." + elif [[ "${BLOCK_NAME}" == "cpu" ]]; then + BLOCK_MESSAGE="CPU utilization is now ${BLOCK_VALUE}." + elif [[ "${BLOCK_NAME}" == "feed" ]]; then + BLOCK_MESSAGE="Newest article is ${BLOCK_VALUE}." + elif [[ "${BLOCK_NAME}" == "mail" ]]; then + BLOCK_MESSAGE="Unread emails went to ${BLOCK_VALUE}." + elif [[ "${BLOCK_NAME}" == "memory" ]]; then + BLOCK_MESSAGE="Memory utilization is now ${BLOCK_VALUE}." + elif [[ "${BLOCK_NAME}" == "packages" ]]; then + BLOCK_MESSAGE="${BLOCK_VALUE} packages are now ready to update." + elif [[ "${BLOCK_NAME}" == "space" ]]; then + BLOCK_MESSAGE="Space utilization is now ${BLOCK_INSTANCE}." + elif [[ "${BLOCK_NAME}" == "ssid" ]]; then + BLOCK_MESSAGE="SSID changed to ${BLOCK_VALUE}." + elif [[ "${BLOCK_NAME}" == "temperature" ]]; then + BLOCK_MESSAGE="Sensor temperature changed to ${BLOCK_VALUE}." + elif [[ "${BLOCK_NAME}" == "trash" ]]; then + BLOCK_MESSAGE="${BLOCK_VALUE} items are now in the trash." + else + BLOCK_MESSAGE="${BLOCK_UCFIRST} is now ${BLOCK_VALUE}." + fi + + if [[ "${BLOCK_NAME}" == "audio" ]]; then + BLOCK_ICON="audio-volume-high-symbolic" + elif [[ "${BLOCK_NAME}" == "bandwidth" ]]; then + BLOCK_ICON="network-wireless-acquiring-symbolic" + elif [[ "${BLOCK_NAME}" == "battery" ]]; then + BLOCK_ICON="battery-symbolic" + elif [[ "${BLOCK_NAME}" == "bluetooth" ]]; then + BLOCK_ICON="bluetooth-active-symbolic" + elif [[ "${BLOCK_NAME}" == "brightness" ]]; then + BLOCK_ICON="display-brightness-symbolic" + elif [[ "${BLOCK_NAME}" == "cmus" ]]; then + BLOCK_ICON="emblem-music-symbolic" + elif [[ "${BLOCK_NAME}" == "countdown" ]]; then + BLOCK_ICON="document-open-recent-symbolic" + elif [[ "${BLOCK_NAME}" == "cpu" ]]; then + BLOCK_ICON="indicator-cpufreq" + elif [[ "${BLOCK_NAME}" == "datetime" ]]; then + BLOCK_ICON="system-run-symbolic" # TODO + elif [[ "${BLOCK_NAME}" == "device" ]]; then + BLOCK_ICON="system-run-symbolic" # TODO + elif [[ "${BLOCK_NAME}" == "display" ]]; then + BLOCK_ICON="video-display-symbolic" + elif [[ "${BLOCK_NAME}" == "feed" ]]; then + BLOCK_ICON="folder-documents-symbolic" + elif [[ "${BLOCK_NAME}" == "firewall" ]]; then + BLOCK_ICON="changes-prevent-symbolic.svg" # TODO + elif [[ "${BLOCK_NAME}" == "ip-address" ]]; then + BLOCK_ICON="avatar-default-symbolic" # TODO + elif [[ "${BLOCK_NAME}" == "keystate" ]]; then + BLOCK_ICON="format-text-underline-symbolic" # TODO + elif [[ "${BLOCK_NAME}" == "launcher" ]]; then + BLOCK_ICON="system-run-symbolic" + elif [[ "${BLOCK_NAME}" == "load" ]]; then + BLOCK_ICON="indicator-cpufreq" # TODO + elif [[ "${BLOCK_NAME}" == "locale" ]]; then + BLOCK_ICON="format-text-larger-symbolic" + elif [[ "${BLOCK_NAME}" == "mail" ]]; then + BLOCK_ICON="mail-send-symbolic" + elif [[ "${BLOCK_NAME}" == "memory" ]]; then + BLOCK_ICON="drive-harddisk-solidstate-symbolic" # TODO + elif [[ "${BLOCK_NAME}" == "microphone" ]]; then + BLOCK_ICON="audio-input-microphone-symbolic" + elif [[ "${BLOCK_NAME}" == "network" ]]; then + BLOCK_ICON="network-wireless-connected-symbolic" + elif [[ "${BLOCK_NAME}" == "packages" ]]; then + BLOCK_ICON="view-refresh-symbolic" + elif [[ "${BLOCK_NAME}" == "playerctl" ]]; then + BLOCK_ICON="emblem-music-symbolic" + elif [[ "${BLOCK_NAME}" == "process" ]]; then + BLOCK_ICON="process-stop-symbolic" + elif [[ "${BLOCK_NAME}" == "space" ]]; then + BLOCK_ICON="drive-harddisk-solidstate-symbolic" # TODO + elif [[ "${BLOCK_NAME}" == "ssid" ]]; then + BLOCK_ICON="system-users-symbolic" + elif [[ "${BLOCK_NAME}" == "temperature" ]]; then + BLOCK_ICON="object-inverse" # TODO + elif [[ "${BLOCK_NAME}" == "trash" ]]; then + BLOCK_ICON="user-trash-symbolic" + elif [[ "${BLOCK_NAME}" == "usb" ]]; then + BLOCK_ICON="drive-removable-media-usb-symbolic-1" + elif [[ "${BLOCK_NAME}" == "vpn" ]]; then + BLOCK_ICON="dialog-password-symbolic" # TODO + elif [[ "${BLOCK_NAME}" == "weather" ]]; then + BLOCK_ICON="weather-few-clouds-symbolic" + elif [[ "${BLOCK_NAME}" == "webcam" ]]; then + BLOCK_ICON="camera-web-symbolic" + elif [[ "${BLOCK_NAME}" == "window" ]]; then + BLOCK_ICON="view-dual-symbolic" # TODO + fi + + if [[ "${BLOCK_URGENT}" -gt 0 ]]; then + notify-send -u critical -t 5000 -i "${BLOCK_ICON}" -a "i3block-${BLOCK_NAME}" "${BLOCK_UCFIRST}" "${BLOCK_MESSAGE}" + else + notify-send -u normal -t 3500 -i "${BLOCK_ICON}" -a "i3block-${BLOCK_NAME}" "${BLOCK_UCFIRST}" "${BLOCK_MESSAGE}" + fi + fi + + if [[ "${VALUE_CHANGED}" -eq 1 ]] || [[ "${HAS_CACHEFILE}" -eq 0 ]]; then + echo "${BLOCK_VALUE}" > "${CACHE_FILE}" + fi +fi + +echo "${BLOCK_OUT}" +exit "${BLOCK_URGENT}"
\ No newline at end of file diff --git a/.i3-blocks/blocks/packages b/.i3-blocks/blocks/packages new file mode 100755 index 0000000..923d479 --- /dev/null +++ b/.i3-blocks/blocks/packages @@ -0,0 +1,20 @@ +#!/usr/bin/bash + +PACKAGES=$(pacman -Qu) + +URGENT_VALUE=25 + +if [[ $? -gt 0 ]]; then + return +fi + +PACKAGE_COUNT=$(echo "${PACKAGES}" | wc -l) + +if [[ "${PACKAGE_COUNT}" -gt 0 ]]; then + echo "${PACKAGE_COUNT}" # full-text + echo "${PACKAGE_COUNT}" # short-text + echo "" + if [[ "${PACKAGE_COUNT}" -gt "${URGENT_VALUE}" ]]; then + exit 33 + fi +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/playerctl b/.i3-blocks/blocks/playerctl new file mode 100755 index 0000000..6d613ed --- /dev/null +++ b/.i3-blocks/blocks/playerctl @@ -0,0 +1,39 @@ +#!/bin/bash +# Based on https://aur.archlinux.org/packages/playerctl/ + +INSTANCE="${BLOCK_INSTANCE}" + +if [[ "${INSTANCE}" != "" ]]; then + ARGUMENTS="--player ${INSTANCE}" +fi + +ICON_PLAY="➤" +ICON_PAUSE="Ⅱ" +ICON_STOP="≠" +CUR_ICON="" + +if [[ "${BLOCK_BUTTON}" -eq 1 ]]; then + $(playerctl ${ARGUMENTS} previous) +elif [[ "${BLOCK_BUTTON}" -eq 2 ]]; then + $(playerctl ${ARGUMENTS} play-pause) +elif [[ "${BLOCK_BUTTON}" -eq 3 ]]; then + $(playerctl ${ARGUMENTS} next) +fi + +PLAYER_STATUS=$(playerctl ${ARGUMENTS} status) +INFO_TITLE=$(playerctl ${ARGUMENTS} metadata title) +INFO_ALBUM=$(playerctl ${ARGUMENTS} metadata album) +INFO_ARTIST=$(playerctl ${ARGUMENTS} metadata artist) + +if [[ "${PLAYER_STATUS}" = "Paused" ]]; then + CUR_ICON="${ICON_PAUSE}" +elif [[ "${PLAYER_STATUS}" = "Playing" ]]; then + CUR_ICON="${ICON_PLAY}" +else + CUR_ICON="${ICON_STOP}" +fi + +if [[ "${INFO_TITLE}" != "" ]] && [[ "${INFO_ARTIST}" != "" ]]; then + echo "${INFO_ARTIST} - ${INFO_TITLE} ${CUR_ICON}" + echo "${INFO_ARTIST} - ${INFO_TITLE} ${CUR_ICON}" +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/process b/.i3-blocks/blocks/process new file mode 100755 index 0000000..078a241 --- /dev/null +++ b/.i3-blocks/blocks/process @@ -0,0 +1,17 @@ +#!/bin/bash + +PROG="${BLOCK_INSTANCE:-i3}" + +PROG_REGEX="["$(echo "${PROG}" | cut -c 1)"]"$(echo "${PROG}" | cut -c 2-)" " +PROCESS=$(ps -eo pid,cmd | grep -w ${PROG_REGEX}) + +if [[ "${PROCESS}" ]]; then + echo "ok" + echo "ok" + echo "" +else + echo "na" + echo "na" + echo "" + exit 33 +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/scroll b/.i3-blocks/blocks/scroll new file mode 100755 index 0000000..677a7fc --- /dev/null +++ b/.i3-blocks/blocks/scroll @@ -0,0 +1,69 @@ +#!/bin/bash +# IMPORTANT: +# To make this block work, you have to edit your block-command. +# It should point to this file. For best performance, only use it on blocks +# which are wide and that you need to scroll. +# +# Example: +# command=~/.i3-blocks/blocks/scroll $BLOCK_NAME +# markup=pango +# interval=repeat + +PROG="${1}" + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +BLOCK_PATH="${SCRIPT_DIR}/${PROG}" + +INTERVAL=0.17 +MAX_LENGTH=25 +ADD_STR=" | " +ADD_LENGTH=${#ADD_STR} + +if [[ -f "${BLOCK_PATH}" ]]; then + BLOCK_OUT=$(bash "${BLOCK_PATH}") + OUT_TEXT=$(echo "${BLOCK_OUT}" | tail -n 1) +elif [[ "${PROG}" != "" ]]; then + OUT_TEXT=$(${PROG}) + if [[ $? -ne 0 ]]; then + sleep 1 + echo "${PROG}" + echo "${PROG}" + exit 33 + fi +fi + +if [[ "${OUT_TEXT}" ]]; then + CHECK_SUM=$(echo "${PROG}-${BLOCK_INSTANCE}" | md5sum | awk '{print $1}') + + TMP_FILE="/tmp/.scroll-${CHECK_SUM}" + + if [[ -f "${TMP_FILE}" ]]; then + SCROLL_POS=$(cat "${TMP_FILE}") + else + SCROLL_POS=0 + fi + + TEXT_LENGTH=${#OUT_TEXT} + MAX_OFFSET=$((TEXT_LENGTH +ADD_LENGTH -1)) + + if [[ "${TEXT_LENGTH}" -lt "${MAX_LENGTH}" ]]; then + MAX_LENGTH="${TEXT_LENGTH}" + fi + + if [[ "${SCROLL_POS}" -gt "${MAX_OFFSET}" ]]; then + SCROLL_POS=0 + fi + + TEXT_LINE="${OUT_TEXT}${ADD_STR}${OUT_TEXT}${ADD_STR}${OUT_TEXT}" + TEXT_LINE=${TEXT_LINE:$SCROLL_POS:$MAX_LENGTH} + + echo "<span font_family='monospace'>${TEXT_LINE}</span>" + echo "<span font_family='monospace'>${TEXT_LINE}</span>" + + SCROLL_POS=$((SCROLL_POS +1)) + + echo "${SCROLL_POS}" > "${TMP_FILE}" + sleep "${INTERVAL}" +else + sleep 1 +fi diff --git a/.i3-blocks/blocks/space b/.i3-blocks/blocks/space new file mode 100755 index 0000000..6e78d19 --- /dev/null +++ b/.i3-blocks/blocks/space @@ -0,0 +1,38 @@ +#!/bin/bash + +INSTANCE="${BLOCK_INSTANCE}" +URGENT_VALUE=90 + +if [[ "${INSTANCE}" = "" ]]; then + INSTANCE="$HOME;free" +fi + +DISPLAY=$(echo "${INSTANCE}" | awk -F ';' '{print $2}') +INSTANCE=$(echo "${INSTANCE}" | awk -F ';' '{print $1}') + +if [[ "${DISPLAY}" = "" ]]; then + DISPLAY="free" +fi + +SPACE_VARS=$(df -h "${INSTANCE}" | tail -n 1 | awk '{$1="";$6="";print $0}') +PERC_SPACE=$(echo "${SPACE_VARS}" | awk -F ' ' '{print $4}' | tr -d '%') + +if [[ "${DISPLAY}" = "max" ]]; then + VALUE=$(echo "${SPACE_VARS}" | awk -F ' ' '{print $1}') +elif [[ "${DISPLAY}" = "used" ]]; then + VALUE=$(echo "${SPACE_VARS}" | awk -F ' ' '{print $2}') +elif [[ "${DISPLAY}" = "free" ]]; then + VALUE=$(echo "${SPACE_VARS}" | awk -F ' ' '{print $3}') +elif [[ "${DISPLAY}" = "perc" ]]; then + VALUE="${PERC_SPACE}%" +fi + +if [[ "${VALUE}" ]]; then + echo "${VALUE}" + echo "${VALUE}" + echo "" +fi + +if [[ "${PERC_SPACE}" -gt "${URGENT_VALUE}" ]]; then + exit 33 +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/ssid b/.i3-blocks/blocks/ssid new file mode 100755 index 0000000..d95c721 --- /dev/null +++ b/.i3-blocks/blocks/ssid @@ -0,0 +1,18 @@ +#!/bin/bash + +SSID_NAME=$(iwgetid -r) + +# You can put any urgent name so the block will give warning +# if a network with this name is used, like public wifi or alike. +# You can separate multiple values with \| +URGENT_VALUE="" + +if [[ "${SSID_NAME}" != "" ]]; then + echo "${SSID_NAME}" + echo "${SSID_NAME}" + echo "" + + if [[ "${URGENT_VALUE}" != "" ]] && [[ $(echo "${SSID_NAME}" | grep -we "${URGENT_VALUE}") != "" ]]; then + exit 33 + fi +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/temperature b/.i3-blocks/blocks/temperature new file mode 100755 index 0000000..0c4b858 --- /dev/null +++ b/.i3-blocks/blocks/temperature @@ -0,0 +1,35 @@ +#!/bin/bash + +TEMP_DEVICE="${BLOCK_INSTANCE:-Core}" +TEMP_OUTPUT=$(sensors | grep "${TEMP_DEVICE}") + +IS_URGENT=0 + +TOTAL_TEMP=0 +TOTAL_COUNT=0 +while read RESULT_LINE; do + TOTAL_COUNT=$((TOTAL_COUNT +1)) + CURRENT_TEMP=$(echo "${RESULT_LINE}" | grep -o -E "[\+\-]?[0-9]*.[0-9]*°C" | sed -n '1p' | tr -d '+°C') + URGENT_VALUE=$(echo "${RESULT_LINE}" | grep -o -E "[\+\-]?[0-9]*.[0-9]*°C" | sed -n '2p' | tr -d '+°C') + + TOTAL_TEMP=$(echo "scale=2;${TOTAL_TEMP}+${CURRENT_TEMP}" | bc -l) + IS_CRITICAL=$(echo "scale=0;${CURRENT_TEMP}-${URGENT_VALUE} >= 0" | bc -l) + + if [[ "${IS_CRITICAL}" -eq 1 ]]; then + IS_URGENT=1 + fi +done <<< "$(echo -e "$TEMP_OUTPUT")" + +AVERAGE_TEMP=$(echo "scale=0;${TOTAL_TEMP}/${TOTAL_COUNT}" | bc -l) + +if [[ "${TOTAL_COUNT}" -gt 1 ]]; then + AVERAGE_TEMP="~ ${AVERAGE_TEMP}" +fi + +echo "${AVERAGE_TEMP}°C" +echo "${AVERAGE_TEMP}°C" +echo "" + +if [[ "${IS_URGENT}" -eq 1 ]]; then + exit 33 +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/trash b/.i3-blocks/blocks/trash new file mode 100755 index 0000000..b567a54 --- /dev/null +++ b/.i3-blocks/blocks/trash @@ -0,0 +1,32 @@ +#!/bin/bash + +TRASH_DIRECTORY="${BLOCK_INSTANCE}" + +if [[ "${TRASH_DIRECTORY}" = "" ]]; then + TRASH_DIRECTORY="${XDG_DATA_HOME:-${HOME}/.local/share}/Trash" +fi + +# Left click +if [[ "${BLOCK_BUTTON}" -eq 1 ]]; then + xdg-open "${TRASH_DIRECTORY}/files" +# Right click +elif [[ "${BLOCK_BUTTON}" -eq 3 ]]; then + # Delete all files permanently (unlink them) + rm -r "${TRASH_DIRECTORY}/files" + rm -r "${TRASH_DIRECTORY}/info" + # Create new directory + mkdir "${TRASH_DIRECTORY}/files" + mkdir "${TRASH_DIRECTORY}/info" +fi + +TRASH_COUNT=$(ls -U -1 "${TRASH_DIRECTORY}/files" | wc -l) + +URGENT_VALUE=100 + +echo "${TRASH_COUNT}" +echo "${TRASH_COUNT}" +echo "" + +if [[ "${TRASH_COUNT}" -ge "${URGENT_VALUE}" ]]; then + exit 33 +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/usb b/.i3-blocks/blocks/usb new file mode 100755 index 0000000..e294e7d --- /dev/null +++ b/.i3-blocks/blocks/usb @@ -0,0 +1,15 @@ +#!/bin/bash + +DEVICE_NAME="${BLOCK_INSTANCE:-Keyboard}" + +DEVICE_INFO=$(lsusb | grep -i "${DEVICE_NAME}") + +if [[ "${DEVICE_INFO}" != "" ]]; then + echo "on" + echo "on" + echo "" +else + echo "na" + echo "na" + echo "" +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/user b/.i3-blocks/blocks/user new file mode 100755 index 0000000..f9391ad --- /dev/null +++ b/.i3-blocks/blocks/user @@ -0,0 +1,9 @@ +#!/usr/bin/bash + +echo "${USER}" +echo "${USER}" +echo "" + +if [[ $(id -u) -eq 0 ]]; then + exit 33 +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/vpn b/.i3-blocks/blocks/vpn new file mode 100755 index 0000000..8e54938 --- /dev/null +++ b/.i3-blocks/blocks/vpn @@ -0,0 +1,9 @@ +#!/bin/bash + +VPNC_FILE='/var/run/vpnc.pid' + +if [[ -e "${VPNC_FILE}" ]]; then + echo "on" + echo "on" + echo "" +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/weather b/.i3-blocks/blocks/weather new file mode 100755 index 0000000..4eb3efe --- /dev/null +++ b/.i3-blocks/blocks/weather @@ -0,0 +1,55 @@ +#!/bin/bash +# Based on http://openweathermap.org/current + +API_KEY="44db6a862fba0b067b1930da0d769e98" + +# Check on http://openweathermap.org/find +CITY_ID="${BLOCK_INSTANCE}" + +URGENT_LOWER=0 +URGENT_HIGHER=30 + +ICON_SUNNY="" +ICON_CLOUDY="" +ICON_RAINY="" +ICON_STORM="" +ICON_SNOW="" +ICON_FOG="" + +SYMBOL_CELSIUS="℃" + +WEATHER_URL="http://api.openweathermap.org/data/2.5/weather?id=${CITY_ID}&appid=${API_KEY}&units=metric" + +WEATHER_INFO=$(wget -qO- "${WEATHER_URL}") +WEATHER_MAIN=$(echo "${WEATHER_INFO}" | grep -o -e '\"main\":\"[a-Z]*\"' | awk -F ':' '{print $2}' | tr -d '"') +WEATHER_TEMP=$(echo "${WEATHER_INFO}" | grep -o -e '\"temp\":\-\?[0-9]*' | awk -F ':' '{print $2}' | tr -d '"') + +if [[ "${WEATHER_MAIN}" = *Snow* ]]; then + echo "${ICON_SNOW} ${WEATHER_TEMP}${SYMBOL_CELSIUS}" + echo "${ICON_SNOW} ${WEATHER_TEMP}${SYMBOL_CELSIUS}" + echo "" +elif [[ "${WEATHER_MAIN}" = *Rain* ]] || [[ "${WEATHER_MAIN}" = *Drizzle* ]]; then + echo "${ICON_RAINY} ${WEATHER_TEMP}${SYMBOL_CELSIUS}" + echo "${ICON_RAINY} ${WEATHER_TEMP}${SYMBOL_CELSIUS}" + echo "" +elif [[ "${WEATHER_MAIN}" = *Cloud* ]]; then + echo "${ICON_CLOUDY} ${WEATHER_TEMP}${SYMBOL_CELSIUS}" + echo "${ICON_CLOUDY} ${WEATHER_TEMP}${SYMBOL_CELSIUS}" + echo "" +elif [[ "${WEATHER_MAIN}" = *Clear* ]]; then + echo "${ICON_SUNNY} ${WEATHER_TEMP}${SYMBOL_CELSIUS}" + echo "${ICON_SUNNY} ${WEATHER_TEMP}${SYMBOL_CELSIUS}" + echo "" +elif [[ "${WEATHER_MAIN}" = *Fog* ]] || [[ "${WEATHER_MAIN}" = *Mist* ]]; then + echo "${ICON_FOG} ${WEATHER_TEMP}${SYMBOL_CELSIUS}" + echo "${ICON_FOG} ${WEATHER_TEMP}${SYMBOL_CELSIUS}" + echo "" +else + echo "${WEATHER_MAIN} ${WEATHER_TEMP}${SYMBOL_CELSIUS}" + echo "${WEATHER_MAIN} ${WEATHER_TEMP}${SYMBOL_CELSIUS}" + echo "" +fi + +if [[ "${WEATHER_TEMP}" -lt "${URGENT_LOWER}" ]] || [[ "${WEATHER_TEMP}" -gt "${URGENT_HIGHER}" ]]; then + exit 33 +fi diff --git a/.i3-blocks/blocks/webcam b/.i3-blocks/blocks/webcam new file mode 100755 index 0000000..3c8eae9 --- /dev/null +++ b/.i3-blocks/blocks/webcam @@ -0,0 +1,17 @@ +#!/bin/bash + +if [[ -c /dev/video0 ]]; then + if [[ "$(fuser /dev/video0)" != "" ]]; then + echo "rec" + echo "rec" + echo "" + else + echo "on" + echo "on" + echo "" + else + echo "off" + echo "off" + echo "" + fi +fi
\ No newline at end of file diff --git a/.i3-blocks/blocks/window b/.i3-blocks/blocks/window new file mode 100644 index 0000000..9ef155a --- /dev/null +++ b/.i3-blocks/blocks/window @@ -0,0 +1,9 @@ +#!/bin/bash + +ACTIVE_WINDOW=$(xprop -id $(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) WM_NAME | cut -d '"' -f 2) + +if [[ "${ACTIVE_WINDOW}" != "" ]]; then + echo "${ACTIVE_WINDOW}" + echo "${ACTIVE_WINDOW}" + echo "" +fi
\ No newline at end of file |