From 6ecc40ac30c7e9d998dd71eccc39f64d3775497c Mon Sep 17 00:00:00 2001 From: typebrook Date: Tue, 17 Mar 2020 10:50:58 +0800 Subject: Fix potential error when getting ID from a given index Originally, if user gives command like 'gist .', _gist_id() still returns true --- gist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gist b/gist index 2b74732..ae9596a 100755 --- a/gist +++ b/gist @@ -406,8 +406,8 @@ _repo_url() { # Get gist id from index files _gist_id() { - GIST_ID=$( (grep -hs '' $INDEX || true) | sed -n -e "/^$1 / p" | cut -d' ' -f2 | sed -E -e 's#.*/##') - if [[ -z $GIST_ID ]]; then + GIST_ID=$(sed -n -e "/^$1 / p" $INDEX | cut -d' ' -f2 | sed -E -e 's#.*/##') + if [[ -z $GIST_ID || ! $1 =~ [0-9a-z]+ ]]; then echo -e "$(hint=false _show_list | sed -Ee 's/^( *[0-9a-z]+)/\\033[5m\1\\033[0m/')" echo echo -e "Not a valid index: \e[33m$1\e[0m" -- cgit v1.2.3-70-g09d2