Skip to content

Commit

Permalink
Merge pull request #338 from Drew-Daniels/gcalcli-support
Browse files Browse the repository at this point in the history
add segment for gcalcli
  • Loading branch information
erikw authored Oct 21, 2023
2 parents 941a9e5 + 93496b6 commit 146b5ce
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ kurczynski
Alejandro Espinosa (Halbard) <[email protected]>
TN Khanh <[email protected]>
Skywarth <[email protected]>
Drew Daniels <[email protected]>
32 changes: 32 additions & 0 deletions segments/gcalcli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Print next Google Calendar Event

TMUX_POWERLINE_SEG_GCALCLI_24HR_TIME_FORMAT_DEFAULT=1

generate_segmentrc() {
read -d '' rccontents << EORC
# gcalcli uses 24hr time format by default - if you want to see 12hr time format, set TMUX_POWERLINE_SEG_GCALCLI_MILITARY_TIME_DEFAULT to 0
export TMUX_POWERLINE_SEG_GCALCLI_24HR_TIME_FORMAT="${TMUX_POWERLINE_SEG_GCALCLI_24HR_TIME_FORMAT_DEFAULT}"
EORC
echo "$rccontents"
}

__process_settings() {
if [ -z "$TMUX_POWERLINE_SEG_GCALCLI_24HR_TIME_FORMAT" ]; then
export TMUX_POWERLINE_SEG_GCALCLI_24HR_TIME_FORMAT="${TMUX_POWERLINE_SEG_GCALCLI_24HR_TIME_FORMAT_DEFAULT}"
fi
}

run_segment() {
if ! command -v gcalcli &> /dev/null
then
echo "'gcalcli' could not be found"
return 1
fi
__process_settings
gcmd=(gcalcli agenda)
if [[ $TMUX_POWERLINE_SEG_GCALCLI_24HR_TIME_FORMAT == 0 ]]; then
gcmd+=(--no-military)
fi
"${gcmd[@]}" | head -2 | tail -1 | sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g' | sed -E 's/ +/ /g'
return 0
}

0 comments on commit 146b5ce

Please sign in to comment.