From 02d414b3ab447e637fef776e387aa5a07293738a Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 2 Jun 2015 15:38:00 +0200 Subject: added command and special Q-Register "$" to set and get the current working directory * FG stands for "Folder Go" * FG behaves similar to a Unix shell `cd`. Without arguments, it changes to the $HOME directory. * The $HOME directory was previously only used by $SCITECOCONFIG on Unix. Now it is documented on its own, since the HOME directory should also be configurable on Windows - e.g. to adapt SciTECO to a MinGW or Cygwin installation. HOME is initialized just like the other environment variables. This also means that now, the $HOME Q-Register is always defined and can be used by platform-agnostic macros. * FG uses a new kind of tab-completion: for directories only. It would be annoying to complete the FG command after every directory, so this tab-completion does not close the command automatically. Theoretically, it would be possible to close the command after completing a directory with no subdirectories, but this is not supported currently. * Filename arguments are no longer completed with " " if {} escaping is in place as this brings no benefit. Instead no completion character is inserted for this escape mode. * "$" was mapped to the current directory to support an elegant way to insert/get the current directory. Also this allows the idiom "[$ FG...new_dir...$ ]$" for changing the current directory temporarily. * The Q-Register stack was extended to support restoring the string part of special Q-Registers (that overwrite the default functionality) when using the "[$" and "]$" commands. * fixed minor typos (american spelling) --- src/main.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 7ad4d80..6966d22 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -121,7 +121,7 @@ get_default_config_path(const gchar *program) static inline gchar * get_default_config_path(const gchar *program) { - return g_strdup(g_getenv("HOME") ? : g_get_home_dir()); + return g_strdup(g_getenv("HOME")); } #else @@ -198,6 +198,18 @@ initialize_environment(const gchar *program) gchar *default_configpath, *abs_path; gchar **env; + /* + * Initialize and canonicalize $HOME. + * Therefore we can refer to $HOME as the + * current user's home directory on any platform + * and it can be re-configured even though g_get_home_dir() + * evaluates $HOME only beginning with glib v2.36. + */ + g_setenv("HOME", g_get_home_dir(), FALSE); + abs_path = get_absolute_path(g_getenv("HOME")); + g_setenv("HOME", abs_path, TRUE); + g_free(abs_path); + /* * Initialize $SCITECOCONFIG and $SCITECOPATH */ @@ -340,6 +352,8 @@ main(int argc, char **argv) QRegisters::globals.insert("-"); /* current buffer name and number ("*") */ QRegisters::globals.insert(new QRegisterBufferInfo()); + /* current working directory ("$") */ + QRegisters::globals.insert(new QRegisterWorkingDir()); /* environment defaults and registers */ initialize_environment(argv[0]); -- cgit v1.2.3