From 9af58572e7d99edd5f0f178bd789b1d36a8e63c6 Mon Sep 17 00:00:00 2001 From: typebrook Date: Sat, 11 Apr 2020 23:10:57 +0800 Subject: Add configuration 'show_untagged' --- README.md | 5 +++++ gist | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 40ad032..0a69575 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,11 @@ valid values are: For example, use `gist config protocol ssh` to use SSH protocol instead. +### show_untagged +**[Optional]** Whether to show untagged gists when using [`gist tag`](#List-gists-with-tags). Default to be `true` + +Use `gist config show_untagged false` to disable this feature. + ## Filter gists ### Filter by tags `gist` treats **trailing hashtags** inside gist description as tags. For example, if a description is: diff --git a/gist b/gist index 9c6bdc6..f4bf032 100755 --- a/gist +++ b/gist @@ -30,7 +30,7 @@ # delete, D ... [--force] Delete gists by given indices # push, P Push changes by git (well, better to make commit by youself) # clean, C Clean local repos of removed gists -# config, c [token|user|folder|auto_sync|EDITOR|action|protocol [value]] Do configuration +# config, c [token|user|folder|auto_sync|EDITOR|action|protocol|show_untagged [value]] Do configuration # user, u Get list of gists with a given Github user # github, G Import selected gist as a new Github repo # help, h Show this help message @@ -170,15 +170,15 @@ update() { _configure() { [[ $# == 0 ]] && (${EDITOR:-vi} "$CONFIG") && return 0 - local valid_keys='user|token|folder|auto_sync|EDITOR|action|protocol' + local valid_keys='user|token|folder|auto_sync|EDITOR|action|protocol|show_untagged' local key=$1; local value="$2" if [[ $key =~ ^($valid_keys)$ ]]; then if [[ $key == 'user' ]]; then [[ -z $value ]] && echo 'Must specify username' >&2 && return 1 elif [[ $key == 'token' ]]; then [[ ${#value} -ne 40 ]] && echo 'Invalid token format, it is not 40 chars' >&2 && return 1 - elif [[ $key == 'auto_sync' ]]; then - [[ ! $value =~ ^(true|false)$ ]] && echo 'auto_sync must be either true or false' >&2 && return 1 + elif [[ $key =~ ^(auto_sync|show_untagged)$ ]]; then + [[ ! $value =~ ^(true|false)$ ]] && echo "$key must be either true or false" >&2 && return 1 elif [[ $key == 'protocol' ]]; then [[ ! $value =~ ^(https|ssh)$ ]] && echo 'protocol must be either https or ssh' >&2 && return 1 fi @@ -309,6 +309,7 @@ _show_list() { local message=$url if [[ $display == 'tag' ]]; then + [[ $show_untagged == 'false' && -z $hashtags ]] && continue message="$hashtags"; local width=45; local align=' '; extra=''; elif [[ $display == 'language' ]]; then message="$(tr ',' '\n' <<< $file_array | sed -Ee 's/.+@/#/' | uniq | xargs)" -- cgit v1.2.3-70-g09d2