aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-04-15 16:37:27 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-04-15 16:37:27 +0200
commit69c43ac9c75c3b3b07845942e9bcf24f78217239 (patch)
tree64bf8bdcb114d6df9781a3aa33280cc97a530fe5
parentf50465312dbb7e8fcb2409aa691d1aea7a43c466 (diff)
downloadvis-69c43ac9c75c3b3b07845942e9bcf24f78217239.tar.gz
vis-69c43ac9c75c3b3b07845942e9bcf24f78217239.tar.xz
vis: improve handling of ~ and environment variables when opening files
-rw-r--r--vis-cmds.c6
-rwxr-xr-xvis-open2
2 files changed, 6 insertions, 2 deletions
diff --git a/vis-cmds.c b/vis-cmds.c
index e58d20a..5b49913 100644
--- 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
index d516ff1..39b8717 100755
--- 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