vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 92c787359504ddf07ae9e423c5cce4b4298b0e37
parent 3502b02a06313da0af1ff460c1946f69fcaed5ee
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Fri, 15 Apr 2016 16:37:27 +0200

vis: improve handling of ~ and environment variables when opening files

Diffstat:
Mvis-cmds.c | 6+++++-
Mvis-open | 2+-
2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/vis-cmds.c b/vis-cmds.c @@ -251,7 +251,11 @@ static bool is_file_pattern(const char *pattern) { struct stat meta; if (stat(pattern, &meta) == 0 && S_ISDIR(meta.st_mode)) return true; - return strchr(pattern, '*') || strchr(pattern, '[') || strchr(pattern, '{'); + for (char special[] = "*?[{$~", *s = special; *s; s++) { + if (strchr(pattern, *s)) + return true; + } + return false; } static const char *file_open_dialog(Vis *vis, const char *pattern) { diff --git a/vis-open b/vis-open @@ -35,7 +35,7 @@ DIR="" [ ! -z "$PATTERN" -a "$PATTERN" != "." -a -d "$PATTERN" ] && DIR="$PATTERN" while true; do - SEL=$({ echo ..; ls -1 $PATTERN; } | $VIS_MENU $VIS_MENU_ARGS) + SEL=$({ echo ..; ls -1 $PATTERN 2>/dev/null || echo $PATTERN; } | $VIS_MENU $VIS_MENU_ARGS) [ -z "$SEL" ] && exit 1 [ ! -z "$DIR" ] && SEL="$DIR/$SEL" if [ -d "$SEL" ]; then