From 239f6431f32dcf9f1368283daf0d65da49ef8e20 Mon Sep 17 00:00:00 2001 From: typebrook Date: Tue, 31 Mar 2020 15:32:47 +0800 Subject: Improve 'gist detail' Make it works without index if working dir is a gist repo --- gist | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/gist b/gist index 5c393d5..0c7a5af 100755 --- a/gist +++ b/gist @@ -466,6 +466,15 @@ _gist_id() { fi } +# set gist id either by given index or current directory +_set_gist_id() { + if [[ -z $1 ]]; then + [[ $(dirname $(pwd)) == $folder ]] && GIST_ID=$(basename $(pwd)) || return 1 + else + _gist_id "$1" || return 1 + fi +} + # Show path of repo by gist ID, and perform action _goto_gist() { echo "$folder/$GIST_ID" @@ -539,8 +548,9 @@ for comment in raw: # Show the detail of a gist # TODO add parameter --comment to fetch comments _show_detail() { - _gist_id "$1" || return 1 - sed -n "/^$1 / p" $INDEX \ + _set_gist_id $1 || return 1 + + sed -En -e "/[^ ]+ [^ ]+$GIST_ID / p" $INDEX \ | while read -r "${INDEX_FORMAT[@]}"; do local hashtags=$(_hashtags "$description") echo desc: ${description%% $hashtags} -- cgit v1.2.3-70-g09d2