-
Notifications
You must be signed in to change notification settings - Fork 926
User Segments
Did you come up with a cool segment that isn't yet ready to contribute to the the powerlevel9k codebase, but that you still want to share? Put them here!
This segment came from #455, and has the neat functionality of updating a multi-line segment based on the TaskWarrior status.
TaskWarrior Download/Build/Install Docs
link to pltask github gist (Star it if you end up using it! 😄)
#pltask functions
## pltask is a lightweight facade to taskwarrior for use with Powerlevel9k's Last Prompt Prefix (by dmidlo @querentCode)
## Be sure to set search.case.sensitive=no within .taskrc
POWERLEVEL9K_PROMPT_ON_NEWLINE=true
POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX="\n"
pltask () {
setNewlinePrompt () {
POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="%K{white}%F{black}\n $1 %f%k%F{white}%f $ "
}
if [ -n "$3" ]; then
echo "pltask only supports two args. did\nyou remember to use quotes when\ncreating a task?"
return 1
elif [ -z "$1" ]; then
export PLTASK=`task _get 1.description`
if [ -z "$PLTASK" ]; then
echo "no tasks in queue, go do something else"
echo "Setting pltask to '.' "
setNewlinePrompt "."
else
echo "Setting pltask to first task from taskwarrior:" $PLTASK
setNewlinePrompt $PLTASK
fi
elif [[ $1 = "_print" || $1 = "_p" ]]; then
echo $PLTASK
elif [[ $1 = "help" || $1 = "h" ]]; then
echo "\n pltask is a lightweight facade to taskwarrior for use with Powerlevel9k's Last Prompt Prefix\n"
echo Options:
echo -----------------------------------------------------------------------------
echo " No args --- Calls first available task from taskwarrior."
echo " help --- h - This help dialog."
echo " list --- ls - A Wrapper for \'task next\'."
echo " set <taskID> --- s - Sets the pltask prompt to description of specified task id."
echo " done --- d - Completes the current task and sets pltask to next task."
echo " \"string\" --- \"string\" with no additional arguments, sets the pltask prompt but no new task."
echo " \"string\" add --- a - \"string\" followed by 'add' will set the pltask and add a new task to taskwarrior.\n\n"
echo Examples:
echo "-----------------------------------------------------------------------------\n"
echo " Create a task:"
echo " $ pltask \"Edit Super Cool Project\" add"
echo " $ pltask \"Write Blog Post\" a"
elif [[ $1 = "list" || $1 = "ls" ]]; then
task next
elif [[ $1 = "set" || $1 = "s" ]]; then
export PLTASK=`task _get $2.description`
if [ -z "$PLTASK" ]; then
export PLTASK=`task _get 1.description`
if [ -z "$PLTASK" ]; then
pltask
else
echo "no task with id $2 in queue"
echo "Setting pltask to first available task: " $PLTASK
setNewlinePrompt $PLTASK
fi
else
echo "Setting pltask to task id $2:" $PLTASK
setNewlinePrompt $PLTASK
fi
elif [[ $1 = "done" || $1 = "d" ]]; then
task /$PLTASK/ done
task
export PLTASK=`task _get 1.description`
if [ -z "$PLTASK" ]; then
pltask
else
echo "Setting pltask to next task: "$PLTASK
setNewlinePrompt $PLTASK
fi
elif [ -z "$2" ]; then
setNewlinePrompt $1
echo "terminal pltask set to " $1 "But no task has been created"
elif [[ $2 = "add" || $2 = "a" ]]; then
export PLTASK="$1"
task "$1" add
task
setNewlinePrompt $1
fi
}
# Initial state
pltask "."
POWERLEVEL9K_CUSTOM_WIFI_SIGNAL="zsh_wifi_signal"
POWERLEVEL9K_CUSTOM_WIFI_SIGNAL_BACKGROUND="blue"
POWERLEVEL9K_CUSTOM_WIFI_SIGNAL_FOREGROUND="yellow"
zsh_wifi_signal(){
local output=$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I)
local airport=$(echo $output | grep 'AirPort' | awk -F': ' '{print $2}')
if [ "$airport" = "Off" ]; then
local color='%F{yellow}'
echo -n "%{$color%}Wifi Off"
else
local ssid=$(echo $output | grep ' SSID' | awk -F': ' '{print $2}')
local speed=$(echo $output | grep 'lastTxRate' | awk -F': ' '{print $2}')
local color='%F{yellow}'
[[ $speed -gt 100 ]] && color='%F{green}'
[[ $speed -lt 50 ]] && color='%F{red}'
echo -n "%{$color%}$ssid $speed Mb/s%{%f%}" # removed char not in my PowerLine font
fi
}This segment reads the current Artist and Track from iTunes via osascript or fetches the data from Spotify using sp, a command line client by Wandernauta for Spotify on dbus
Create a .nowplaying file in your $HOME folder and make it executable with chmod +x
If you are using Spotify on Ubuntu/Debian (or probably any other Linux distribution using dbus) download the sp script and make it executable
wget -O $HOME/sp https://gist.githubusercontent.com/wandernauta/6800547/raw/2c2ad0f3849b1b1cd1116b80718d986f1c1e7966/sp
chmod +x $HOME/spAdd the following code to this file
#! /bin/bash
if [ "$(uname)" = "Darwin" ]; then
echo "\uF001 $(osascript -e 'tell application "iTunes" to if player state is playing then artist of current track & " - " & name of current track')"
else
echo "\uF001 $(~/.dotfiles/bin/sp current | sed '3q;d' | awk '{$1=""; print $0}' | sed 's/^ *//g' | sed 's/ *$//g') - $(~/.dotfiles/bin/sp current | sed '4q;d' | awk '{$1=""; print $0}' | sed 's/^ *//g' | sed 's/ *$//g')"
fiIn your .zshrc add the following code
POWERLEVEL9K_CUSTOM_NOW_PLAYING='~/.nowplaying'
POWERLEVEL9K_CUSTOM_NOW_PLAYING_BACKGROUND='blue'
POWERLEVEL9K_CUSTOM_NOW_PLAYING_FOREGROUND='black'
Now you can add this segment as custom_now_playing to your prompt

