adding flexibility in view options
I am a total hobbyist at this stuff so do tell me if this is dumb or superfluous or whatever.
I enjoy using khal but miss some flexibility in displaying events. Mainly two things:
- I want to look not just days but also weeks or months ahead
- I sometimes want to look back in time
Eg, I want the following command to work:
khal list -3d 2w
which should list everything from 3 days ago up to 2 weeks into the future.
I've made a simple wrapper script that does just that. Works fine. But since it's still a wraparound and feels like the sort of thing that could be incorporated into khal itself, figured I'd post here.
#!/bin/zsh
#input variables start="$1" finish="$2"
#store other arguments shift 2
#build start date if [[ $start == "now" || $start == "yesterday" || $start == "tomorrow" ]]; then khal_start=$start
elif [[ $start =~ ^-?[0-9]+[dwmy]$ ]]; then number="${start%%[dwmy]}" unit="${start: -1}"
case $unit in
d) unit_full=" days" ;;
w) unit_full=" weeks" ;;
m) unit_full=" months" ;;
y) unit_full=" years" ;;
esac
khal_start=$(date -d "$number$unit_full" "+%Y_%m_%d")
fi
#build finish date if [[ $finish == "now" || $finish == "yesterday" || $finish == "tomorrow" ]]; then khal_finish=$finish
elif [[ $finish =~ ^-?[0-9]+[dwmy]$ ]]; then number="${finish%%[dwmy]}" unit="${finish: -1}"
case $unit in
d) unit_full=" days" ;;
w) unit_full=" weeks" ;;
m) unit_full=" months" ;;
y) unit_full=" years" ;;
esac
khal_finish=$(date -d "$number$unit_full" "+%Y_%m_%d")
fi
khal list $khal_start $khal_finish $@