From 489f178d7ce45d401999c56914a251a29c29630b Mon Sep 17 00:00:00 2001 From: Ambrose Chua Date: Tue, 30 Oct 2018 16:34:51 +0800 Subject: [PATCH] Add bitbar --- .bar/addr.10s.sh | 20 ++++++++ .bar/nowplaying.5s.sh | 115 ++++++++++++++++++++++++++++++++++++++++++ .bar/ping.10s.sh | 39 ++++++++++++++ .zshrc | 4 ++ 4 files changed, 178 insertions(+) create mode 100755 .bar/addr.10s.sh create mode 100755 .bar/nowplaying.5s.sh create mode 100755 .bar/ping.10s.sh diff --git a/.bar/addr.10s.sh b/.bar/addr.10s.sh new file mode 100755 index 0000000..b0f2ef9 --- /dev/null +++ b/.bar/addr.10s.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +ACTIVE_INTERFACE=$(route get 1.1.1.1 | grep interface | cut -d ' ' -f 4) + +ADDR=$(ifconfig $ACTIVE_INTERFACE | grep 'inet ' | cut -d ' ' -f 2) +ADDR6=$(ifconfig $ACTIVE_INTERFACE | grep 'inet6 ' | grep -v 'fe80' | cut -d ' ' -f 2) + +echo $ADDR + +echo --- + +for iface in $(ifconfig -lu); do + IFCONFIG_OUTPUT=$(ifconfig $iface) + echo "iface $iface" + echo "$IFCONFIG_OUTPUT" | grep ether | sed -e 's/^[[:space:]]*//' + echo "$IFCONFIG_OUTPUT" | grep 'inet ' | sed -e 's/^[[:space:]]*//' + echo "$IFCONFIG_OUTPUT" | grep 'inet6 ' | grep -v 'fe80' | sed -e 's/^[[:space:]]*//' + echo --- +done + diff --git a/.bar/nowplaying.5s.sh b/.bar/nowplaying.5s.sh new file mode 100755 index 0000000..cf4df47 --- /dev/null +++ b/.bar/nowplaying.5s.sh @@ -0,0 +1,115 @@ +#!/bin/bash + +# Now playing +# v1.1 +# Adam Kenyon +# adampk90 +# Shows and controls the music that is now playing. Currently supports Spotify, iTunes, and Vox. +# https://pbs.twimg.com/media/CbKmTS7VAAA84VS.png:small +# +# + +# first, determine if there's an app that's playing or paused +apps=(Spotify iTunes Vox) +playing="" +paused="" + +for i in "${apps[@]}"; do + # is the app running? + app_state=$(osascript -e "application \"$i\" is running") + + # shellcheck disable=SC2181 + if [ "$?" != "0" ]; then + # just exit if there was an error determining the app's state + # (the app might be in the middle of quitting) + exit + fi + + if [ "$app_state" = "true" ] && [ "$track" = "" ]; then + # yes, it's running + # is it playing music currently? + app_playing=$(osascript -e "tell application \"$i\" to player state as string") + if [ "$app_playing" = "paused" ] || [ "$app_playing" = "0" ]; then + # nope, it's paused + paused="$i" + elif [ "$app_playing" = "playing" ] || [ "$app_playing" = "1" ]; then + # yes, it's playing + playing="$i" + fi + fi +done + + +# open a specified app +if [ "$1" = "open" ]; then + osascript -e "tell application \"$2\" to activate" + exit +fi +# play/pause +if [ "$1" = "play" ] || [ "$1" = "pause" ]; then + osascript -e "tell application \"$2\" to $1" + exit +fi +# next/previous +if [ "$1" = "next" ] || [ "$1" = "previous" ]; then + osascript -e "tell application \"$2\" to $1 track" + # tell spotify to hit "Previous" twice so it actually plays the previous track + # instead of just starting from the beginning of the current one + if [ "$playing" = "Spotify" ] && [ "$1" = "previous" ]; then + osascript -e "tell application \"$2\" to $1 track" + fi + osascript -e "tell application \"$2\" to play" + exit +fi + + +# start outputting information to bitbar +if [ "$playing" = "" ] && [ "$paused" = "" ]; then + # nothing is even paused + echo "🙉 No music playing | color=gray" +else + # something is playing or is paused + track="" + artist="" + + if [ "$playing" = "" ]; then + echo "$paused is paused | color=#888888" + echo "---" + app="$paused" + else + app="$playing" + fi + + track_query="name of current track" + artist_query="artist of current track" + # Vox uses a different syntax for track and artist names + if [ "$app" = "Vox" ]; then + track_query="track" + artist_query="artist" + fi + + # output the track and artist + track=$(osascript -e "tell application \"$app\" to $track_query") + artist=$(osascript -e "tell application \"$app\" to $artist_query") + + echo "$track | length=40" | awk -F '\ -' '{print $1}' + echo "---" + echo "$artist" + + if [ "$playing" != "" ]; then + echo "Now playing on $app | color=gray bash='$0' param1=open param2=$app terminal=false" + echo "---" + echo "⏸ Pause | bash='$0' param1=pause param2=$app refresh=true terminal=false" + else + echo "▶️ Play | bash='$0' param1=play param2=$app refresh=true terminal=false" + fi + + echo "⏭ Next | bash='$0' param1=next param2=$app refresh=true terminal=false" + echo "⏮ Previous | bash='$0' param1=previous param2=$app refresh=true terminal=false" +fi + +# add an Open option for each service +echo "---" +for i in "${apps[@]}"; do + echo "Open $i | bash='$0' param1=open param2=$i terminal=false" +done diff --git a/.bar/ping.10s.sh b/.bar/ping.10s.sh new file mode 100755 index 0000000..a05217f --- /dev/null +++ b/.bar/ping.10s.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +SPEED_FILE=/tmp/speedtest.log + +if [[ "$1" == "speedtest" ]]; then + speedtest --bytes --timeout 10 --simple > /tmp/speedtest.log + echo "Updated: $(date +%H:%M:%S)" >> /tmp/speedtest.log +fi + +PING_ADDR=twitter.com +PING_STATS=$(ping -c 10 -i 0.1 $PING_ADDR | tail -n 2) + +PING_NAMES=$(echo "$PING_STATS" | tail -n 1 | cut -d ' ' -f 2) +PING_TIMES=$(echo "$PING_STATS" | tail -n 1 | cut -d ' ' -f 4) + +loss=$(echo "$PING_STATS" | head -n 1 | cut -d ' ' -f 7) +avg=$(echo $PING_TIMES | cut -d '/' -f 2 | tr -d $'\n') + +echo "${avg}ms $loss" + +echo --- + +echo "address $PING_ADDR" + +echo "loss $LOSS" + +for i in {1..3}; do + name=$(echo $PING_NAMES | cut -d '/' -f $i | tr -d $'\n') + time=$(echo $PING_TIMES | cut -d '/' -f $i | tr -d $'\n') + echo "$name ${time}ms" +done + +echo --- + +if [[ -f /tmp/speedtest.log ]]; then + cat $SPEED_FILE +fi + +echo "Run speedtest | bash='./ping.10s.sh' param1='speedtest' terminal=false" diff --git a/.zshrc b/.zshrc index 8f649a8..2f6f9c4 100644 --- a/.zshrc +++ b/.zshrc @@ -35,6 +35,10 @@ if [[ "$(uname -s)" -eq "Darwin" ]]; then else eval $(dircolors -b $HOME/.dircolors) fi +zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} + +# completion menu +zstyle ':completion:*' menu select # editor export EDITOR=nvim