From 69a0543263e793a94507d3cf40da73710eb04774 Mon Sep 17 00:00:00 2001 From: typebrook Date: Sat, 28 Mar 2020 09:53:13 +0800 Subject: Add subcommand 'gist last' --- gist | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/gist b/gist index b1bfda9..ef6a6ba 100755 --- a/gist +++ b/gist @@ -465,8 +465,7 @@ _gist_id() { } # Return the path of local repo with a given index -# If action is not empty, eval it! -_goto_gist() { +_goto_gist_by_index() { _gist_id "$1" || return 1 if [[ ! -d $folder/$GIST_ID ]]; then @@ -479,7 +478,13 @@ _goto_gist() { fi fi + _goto_gist +} + +_goto_gist() { echo "$folder/$GIST_ID" + touch "$folder/$GIST_ID" + if [[ -z $action ]]; then action='echo Inside subshell, press \ to exit; ${SHELL:-bash}' fi @@ -771,6 +776,11 @@ _gists_with_range() { hint=false _show_list } +_access_last_index() { + GIST_ID=$(ls -tup $folder | grep / | head -1) + _goto_gist +} + _apply_config "$@" || exit 1 getConfiguredClient || exit 1 if [[ $init ]]; then _fetch_gists; exit 0; fi @@ -827,6 +837,8 @@ case "$1" in _gists_with_languages "$@" ;; *-*) _gists_with_range "$@" ;; + last | L) + _access_last_index ;; version) echo "Version $currentVersion" ;; update) @@ -835,5 +847,5 @@ case "$1" in help | h) usage ;; *) - _goto_gist "$@" ;; + _goto_gist_by_index "$@" ;; esac -- cgit v1.2.3-70-g09d2