diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2015-06-12 15:12:59 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2015-06-12 15:12:59 +0200 |
commit | 7919aca84cdea7746b60fec9795e9617c266dd1d (patch) | |
tree | 90db8c7d899b69014d085af0cf3327741691df6a /src/ioview.cpp | |
parent | 3551924ccd580a59190ac80e25c59b729ec4f613 (diff) | |
download | sciteco-7919aca84cdea7746b60fec9795e9617c266dd1d.tar.gz |
support UNIX-shell-like tilde-expansions in file names and directories
* expands to the value of $HOME (the env variable instead of
the register which currently makes a slight difference).
* supported for tab-completions
* supported for all file-name accepting commands.
The expansion is done centrally in StateExpectFile::done().
A new virtual method StateExpectFile::got_file() has been
introduced to pass the expanded/processed file name to
command implementations.
* sciteco(7) has been updated: There is now a separate section
on file name arguments and file name handling in SciTECO.
This information is important but has been scattered across
the document previously.
* optimized is_glob_pattern() in glob.h
Diffstat (limited to 'src/ioview.cpp')
-rw-r--r-- | src/ioview.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/ioview.cpp b/src/ioview.cpp index 323377f..e43fc2c 100644 --- a/src/ioview.cpp +++ b/src/ioview.cpp @@ -669,6 +669,33 @@ IOView::save(const gchar *filename) /* * Auxiliary functions */ + +/** + * Perform tilde expansion on a file name or path. + * + * This supports only strings with a "~" prefix. + * A user name after "~" is not supported. + * The $HOME environment variable is used to retrieve + * the current user's home directory. + */ +gchar * +expand_path(const gchar *path) +{ + if (!path) + path = ""; + + if (path[0] != '~' || (path[1] && !G_IS_DIR_SEPARATOR(path[1]))) + return g_strdup(path); + + /* + * $HOME should not have a trailing directory separator since + * it is canonicalized to an absolute path at startup, + * but this ensures that a proper path is constructed even if + * it does (e.g. $HOME is changed later on). + */ + return g_build_filename(g_getenv("HOME"), path+1, NIL); +} + #ifdef G_OS_UNIX gchar * |