diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/gist | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/scripts/gist b/scripts/gist index 2f0a3f7..59fbd06 100755 --- a/scripts/gist +++ b/scripts/gist | |||
| @@ -115,11 +115,11 @@ update() { | |||
| 115 | echo "Error: no active internet connection" >&2 | 115 | echo "Error: no active internet connection" >&2 |
| 116 | exit 1 | 116 | exit 1 |
| 117 | else | 117 | else |
| 118 | if [[ "$latestVersion" != "$currentVersion" ]]; then | 118 | if [[ $latestVersion != $currentVersion ]]; then |
| 119 | echo "Version $latestVersion available" | 119 | echo "Version $latestVersion available" |
| 120 | echo -n "Do you wish to update $repositoryName [Y/n]: " | 120 | echo -n "Do you wish to update $repositoryName [Y/n]: " |
| 121 | read -r answer | 121 | read -r answer |
| 122 | if [[ "$answer" == [Yy] ]]; then | 122 | if [[ $answer == [Yy] ]]; then |
| 123 | cd ~ || { echo 'Update Failed'; exit 1; } | 123 | cd ~ || { echo 'Update Failed'; exit 1; } |
| 124 | if [[ -d ~/$repositoryName ]]; then rm -r -f $repositoryName || { echo "Permissions Error: try running the update as sudo"; exit 1; } ; fi | 124 | if [[ -d ~/$repositoryName ]]; then rm -r -f $repositoryName || { echo "Permissions Error: try running the update as sudo"; exit 1; } ; fi |
| 125 | echo -n "Downloading latest version of: $repositoryName." | 125 | echo -n "Downloading latest version of: $repositoryName." |
| @@ -144,7 +144,7 @@ update() { | |||
| 144 | 144 | ||
| 145 | # handle configuration cases | 145 | # handle configuration cases |
| 146 | _configure() { | 146 | _configure() { |
| 147 | [[ -z "$@" ]] && (${EDITOR:-vi} $CONFIG) && return 0 | 147 | [[ -z $@ ]] && (${EDITOR:-vi} $CONFIG) && return 0 |
| 148 | 148 | ||
| 149 | local target="" | 149 | local target="" |
| 150 | if [[ $1 =~ ^(user|token|folder|auto_sync|EDITOR|action)$ ]]; then | 150 | if [[ $1 =~ ^(user|token|folder|auto_sync|EDITOR|action)$ ]]; then |
| @@ -160,7 +160,7 @@ _configure() { | |||
| 160 | fi | 160 | fi |
| 161 | 161 | ||
| 162 | umask 0077 && touch $CONFIG | 162 | umask 0077 && touch $CONFIG |
| 163 | sed -i'' -e "/^$1=/ d" $CONFIG && [[ -n "$target" ]] && echo $target >> $CONFIG | 163 | sed -i'' -e "/^$1=/ d" $CONFIG && [[ -n $target ]] && echo $target >> $CONFIG |
| 164 | cat $CONFIG | 164 | cat $CONFIG |
| 165 | } | 165 | } |
| 166 | 166 | ||
| @@ -315,7 +315,7 @@ _fetch_gists() { | |||
| 315 | echo | 315 | echo |
| 316 | local route="users/$user/gists" | 316 | local route="users/$user/gists" |
| 317 | local filter='/^[^s]/ d; /^$/ d' | 317 | local filter='/^[^s]/ d; /^$/ d' |
| 318 | if [[ "$1" =~ ^(star|s)$ ]];then | 318 | if [[ $1 =~ ^(star|s)$ ]];then |
| 319 | route="gists/starred" | 319 | route="gists/starred" |
| 320 | local mark="s" | 320 | local mark="s" |
| 321 | filter='/^[s]/ d; /^$/ d' | 321 | filter='/^[s]/ d; /^$/ d' |
| @@ -369,7 +369,7 @@ _sync_repos() { | |||
| 369 | # get gist id from index files | 369 | # get gist id from index files |
| 370 | _gist_id() { | 370 | _gist_id() { |
| 371 | GIST_ID=$( (grep -hs '' $INDEX || true) | sed -n -e "/^$1 / p" | cut -d' ' -f2 | sed -E -e 's#.*/##') | 371 | GIST_ID=$( (grep -hs '' $INDEX || true) | sed -n -e "/^$1 / p" | cut -d' ' -f2 | sed -E -e 's#.*/##') |
| 372 | if [[ -z "$GIST_ID" ]]; then | 372 | if [[ -z $GIST_ID ]]; then |
| 373 | echo -e "Not a valid index: \e[31m$1\e[0m" | 373 | echo -e "Not a valid index: \e[31m$1\e[0m" |
| 374 | echo Use the index in the first column instead: | 374 | echo Use the index in the first column instead: |
| 375 | echo | 375 | echo |
| @@ -400,7 +400,7 @@ _goto_gist() { | |||
| 400 | _delete_gist() { | 400 | _delete_gist() { |
| 401 | read -r -p "Delete gists above? [y/N] " response | 401 | read -r -p "Delete gists above? [y/N] " response |
| 402 | response=${response,,} | 402 | response=${response,,} |
| 403 | [[ ! "$response" =~ ^(yes|y)$ ]] && return 0 | 403 | [[ ! $response =~ ^(yes|y)$ ]] && return 0 |
| 404 | 404 | ||
| 405 | for i in "$@"; do | 405 | for i in "$@"; do |
| 406 | _gist_id "$i" | 406 | _gist_id "$i" |
| @@ -460,7 +460,7 @@ _show_detail() { | |||
| 460 | # set filename/description/permission for a new gist | 460 | # set filename/description/permission for a new gist |
| 461 | _set_gist() { | 461 | _set_gist() { |
| 462 | public=True | 462 | public=True |
| 463 | while [[ -n "$@" ]]; do case $1 in | 463 | while [[ -n $@ ]]; do case $1 in |
| 464 | -d | --desc) | 464 | -d | --desc) |
| 465 | description="$2" | 465 | description="$2" |
| 466 | shift; shift;; | 466 | shift; shift;; |
| @@ -484,7 +484,7 @@ _new_file() { | |||
| 484 | tmp_file=$(mktemp) | 484 | tmp_file=$(mktemp) |
| 485 | cat > $tmp_file | 485 | cat > $tmp_file |
| 486 | echo -e '\n' > /dev/tty | 486 | echo -e '\n' > /dev/tty |
| 487 | [[ -z "$1" ]] && read -p 'Type file name: ' filename < /dev/tty | 487 | [[ -z $1 ]] && read -p 'Type file name: ' filename < /dev/tty |
| 488 | mv $tmp_file /tmp/$filename | 488 | mv $tmp_file /tmp/$filename |
| 489 | echo /tmp/$filename | 489 | echo /tmp/$filename |
| 490 | } | 490 | } |
| @@ -505,8 +505,8 @@ print(json.dumps({'public': $public, 'files': files_json, 'description': descrip | |||
| 505 | # create a new gist with files | 505 | # create a new gist with files |
| 506 | _create_gist() { | 506 | _create_gist() { |
| 507 | _set_gist "$@" || return 1 | 507 | _set_gist "$@" || return 1 |
| 508 | [[ -z "$files" ]] && files=$(_new_file $filename) | 508 | [[ -z $files ]] && files=$(_new_file $filename) |
| 509 | [[ -z "$description" ]] && read -p 'Type description: ' description < /dev/tty | 509 | [[ -z $description ]] && read -p 'Type description: ' description < /dev/tty |
| 510 | 510 | ||
| 511 | echo 'Creating a new gist...' | 511 | echo 'Creating a new gist...' |
| 512 | http_data=$(mktemp) | 512 | http_data=$(mktemp) |
| @@ -548,7 +548,7 @@ usage() { | |||
| 548 | _apply_config "$@" || exit 1 | 548 | _apply_config "$@" || exit 1 |
| 549 | getConfiguredClient || exit 1 | 549 | getConfiguredClient || exit 1 |
| 550 | if [[ $init ]]; then _fetch_gists; exit 0; fi | 550 | if [[ $init ]]; then _fetch_gists; exit 0; fi |
| 551 | [[ -z "$hint" ]] && hint=true | 551 | [[ -z $hint ]] && hint=true |
| 552 | case "$1" in | 552 | case "$1" in |
| 553 | "") | 553 | "") |
| 554 | hint=$hint _show_list ;; | 554 | hint=$hint _show_list ;; |