diff options
Diffstat (limited to 'shenanigans.sh')
| -rwxr-xr-x | shenanigans.sh | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/shenanigans.sh b/shenanigans.sh index 29dbf0a..ce71021 100755 --- a/shenanigans.sh +++ b/shenanigans.sh | |||
| @@ -44,6 +44,9 @@ export PATH=$HOME/Applications:$PATH | |||
| 44 | export PATH=$HOME/go/bin:$PATH | 44 | export PATH=$HOME/go/bin:$PATH |
| 45 | export PATH=/usr/local/go/bin:$PATH | 45 | export PATH=/usr/local/go/bin:$PATH |
| 46 | 46 | ||
| 47 | # Other paths. | ||
| 48 | export PATH=$HOME/.local/bin/odin-linux-amd64-dev-2024-1:$PATH | ||
| 49 | |||
| 47 | # History and search. Stolen from J. | 50 | # History and search. Stolen from J. |
| 48 | HISTCONTROL=ignoreboth | 51 | HISTCONTROL=ignoreboth |
| 49 | shopt -s histappend | 52 | shopt -s histappend |
| @@ -95,3 +98,76 @@ backup() { | |||
| 95 | cd $CWD | 98 | cd $CWD |
| 96 | } | 99 | } |
| 97 | 100 | ||
| 101 | export TICKETS=~/Vault/tickets | ||
| 102 | tt() { # https://github.com/mitjafelicijan/ticket | ||
| 103 | if [ "$(uname -s)" != "Linux" ]; then | ||
| 104 | printf "Currently only Linux is supported.\n" | ||
| 105 | return 1 | ||
| 106 | fi | ||
| 107 | |||
| 108 | if [ -z "$TICKETS" ]; then | ||
| 109 | TICKETS="$HOME/tickets" | ||
| 110 | fi | ||
| 111 | |||
| 112 | mkdir -p $TICKETS | ||
| 113 | |||
| 114 | # Display open tickets if no argument provided. | ||
| 115 | if [ -z "$1" ]; then | ||
| 116 | echo "`tt -o`" | ||
| 117 | return 0 | ||
| 118 | fi | ||
| 119 | |||
| 120 | case $1 in | ||
| 121 | -n|-new) | ||
| 122 | ticket_id=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 10 | head -n 1) | ||
| 123 | ticket_file=$TICKETS/$ticket_id | ||
| 124 | printf "id: %s\n" $ticket_id > $ticket_file | ||
| 125 | printf "responsible: %s\n" `whoami`@`hostname` >> $ticket_file | ||
| 126 | printf "created: %s\n" "`date`" >> $ticket_file | ||
| 127 | printf "status: open\n" >> $ticket_file | ||
| 128 | printf "title: ?\n" >> $ticket_file | ||
| 129 | printf "====\n" >> $ticket_file | ||
| 130 | printf "Describe your problem here\n" >> $ticket_file | ||
| 131 | $EDITOR $ticket_file | ||
| 132 | ;; | ||
| 133 | -o|-open) | ||
| 134 | printf "%-12s %-21s %s\n" "Ticket ID" "Created at" "Title" | ||
| 135 | printf "%0.s-" {1..100} | ||
| 136 | printf "\n" | ||
| 137 | grep --color=never -l 'status: open' $TICKETS/* | while read file; do | ||
| 138 | id=$(head -n 1 "$file" | tail -n 1 | awk '{ print $2 }') | ||
| 139 | title=$(head -n 5 "$file" | tail -n 1 | awk '{$1=""; print $0}') | ||
| 140 | cdate=$(head -n 3 "$file" | tail -n 1 | awk '{$1=""; print $0}') | ||
| 141 | cdate_fmt=$(date -d "$cdate" "+%Y-%m-%d %H:%M:%S") | ||
| 142 | printf "%-12s %-20s %.66s\n" "$id" "$cdate_fmt" "$title" | ||
| 143 | done | ||
| 144 | ;; | ||
| 145 | -c|-closed) | ||
| 146 | printf "%-12s %-21s %s\n" "Ticket ID" "Created at" "Title" | ||
| 147 | printf "%0.s-" {1..100} | ||
| 148 | printf "\n" | ||
| 149 | grep --color=never -l 'status: closed' $TICKETS/* | while read file; do | ||
| 150 | id=$(head -n 1 "$file" | tail -n 1 | awk '{ print $2 }') | ||
| 151 | title=$(head -n 5 "$file" | tail -n 1 | awk '{$1=""; print $0}') | ||
| 152 | cdate=$(head -n 3 "$file" | tail -n 1 | awk '{$1=""; print $0}') | ||
| 153 | cdate_fmt=$(date -d "$cdate" "+%Y-%m-%d %H:%M:%S") | ||
| 154 | printf "%-12s %-20s %.66s\n" "$id" "$cdate_fmt" "$title" | ||
| 155 | done | ||
| 156 | ;; | ||
| 157 | -h|-help) | ||
| 158 | printf "Usage: ticket [option]\n" | ||
| 159 | printf " -n, -new creates a new ticket\n" | ||
| 160 | printf " -o, -open lists open tickets\n" | ||
| 161 | printf " -c, -closed lists closed tickets\n" | ||
| 162 | printf " -h, -help shows this help\n" | ||
| 163 | ;; | ||
| 164 | *) | ||
| 165 | if [ -e "$TICKETS/$1" ] && [ -f "$TICKETS/$1" ]; then | ||
| 166 | $EDITOR "$TICKETS/$1" | ||
| 167 | else | ||
| 168 | printf "Ticket not found: $TICKETS/$1\n" | ||
| 169 | fi | ||
| 170 | ;; | ||
| 171 | esac | ||
| 172 | } | ||
| 173 | |||
