From bb284f692624c3a47af7c5e8505b3dbf14108d5e Mon Sep 17 00:00:00 2001 From: Tamas Pal Date: Mon, 7 Jul 2014 11:35:44 +0200 Subject: [PATCH 1/3] mad: handle if the script is symlinked If the called script is a symlink, resolve said symlink to find the proper install path. Requires readlink(1). --- bin/mad | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/mad b/bin/mad index 253a61e..8b41711 100755 --- a/bin/mad +++ b/bin/mad @@ -3,7 +3,13 @@ VERSION="0.4.1" REMOTE=git://github.com/visionmedia/mad-pages.git REMOTE_MAD=git://github.com/visionmedia/mad.git -CONFIG=$(dirname $0)/../etc/mad.conf + +BINPATH=$0 +if [ -h "$BINPATH" ]; then + BINPATH=$(readlink "$BINPATH") +fi +MAD_ROOT=$(dirname "$BINPATH") +CONFIG=${MAD_ROOT}/../etc/mad.conf MAD_CONFIG=${MAD_CONFIG:-$CONFIG} # @@ -36,7 +42,7 @@ list_pages() { display() { IFS=":" local page=$1 - local paths=".:$MAD_PATH:$(dirname $0)/../share/mad:/usr/share/mad" + local paths=".:$MAD_PATH:${MAD_ROOT}/../share/mad:/usr/share/mad" for path in $paths; do local file=$path/$page @@ -98,7 +104,7 @@ display_file() { # display_mad_usage() { - display_file $(dirname $0)/../share/mad/mad.md + display_file ${MAD_ROOT}/../share/mad/mad.md exit } @@ -107,7 +113,7 @@ display_mad_usage() { # install_all_remote() { - local path=$(dirname $0)/../share/mad + local path=${MAD_ROOT}/../share/mad echo echo " ... cloning repo" cd /tmp && rm -fr mad-pages From d4fc506e6e316bb368b31528ac4edd535e276e8e Mon Sep 17 00:00:00 2001 From: Tamas Pal Date: Mon, 7 Jul 2014 11:38:23 +0200 Subject: [PATCH 2/3] mad: get() matches the keyword properly grep matches the full keyword, ending with ':', to avoid false positives from comments and/or matches frm other keywords. --- bin/mad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/mad b/bin/mad index 8b41711..5fcb61d 100755 --- a/bin/mad +++ b/bin/mad @@ -64,7 +64,7 @@ display() { # get() { - grep "$1" "$MAD_CONFIG" | awk '{ print $2 }' + grep "^$1:" "$MAD_CONFIG" | awk '{ print $2 }' } # From 423e2fdc27bb7da40295df4a274fccb3de1803c6 Mon Sep 17 00:00:00 2001 From: Pepe Doval Date: Wed, 25 Jun 2014 10:08:44 +0200 Subject: [PATCH 3/3] Some style for links --- bin/mad | 3 +++ etc/mad.conf | 2 ++ 2 files changed, 5 insertions(+) diff --git a/bin/mad b/bin/mad index 5fcb61d..c8062b3 100755 --- a/bin/mad +++ b/bin/mad @@ -82,6 +82,8 @@ display_from_stdin() { display_file() { local heading=$(get heading) local code=$(get code) + local link=$(get link) + local url=$(get url) local strong=$(get strong) local em=$(get em) @@ -93,6 +95,7 @@ display_file() { s|\*(.+?)\*|\e[$em\1\e[0m|g; \ s|_(.+?)_|\e[$em\1\e[0m|g; \ s| (.+)| \e[$code\1\e[0m|g; \ + s|\[(.+)\]\((.+)\)|\e[$em\e[$link\1\e[0m \e[$url(\2)\e[0m|g; \ s|<(.+?)>||g; \ s|^| |;" \ | less -R diff --git a/etc/mad.conf b/etc/mad.conf index 881519b..bd1fb34 100644 --- a/etc/mad.conf +++ b/etc/mad.conf @@ -2,3 +2,5 @@ heading: 1m code: 90m strong: 1m em: 4m +link: 4;34;48m +url: 90m