Parcourir la source

init: Change the history file according to mapset for zsh (#975)

* A new prompt code for zsh for switching the history as bash has since #930 (2d24a42cd4b6c66ab81348aa61240e784df39032).
* No need to warn about history for zsh in g.mapset.
nilason il y a 4 ans
Parent
commit
ac85396bd9
2 fichiers modifiés avec 13 ajouts et 14 suppressions
  1. 6 13
      general/g.mapset/main.c
  2. 7 1
      lib/init/grass.py

+ 6 - 13
general/g.mapset/main.c

@@ -203,25 +203,18 @@ int main(int argc, char *argv[])
     G_free(mapset_old_path);
 
     shell = getenv("SHELL");
-    /* For bash, we support switching of history, others not (yet). */
-    if (shell && strstr(shell, "bash")) {
+    /* For bash and zsh, we support switching of history, tcsh not (yet). */
+    if (shell && (strstr(shell, "bash") || strstr(shell, "zsh"))) {
 	G_important_message(_("Mapset switched."));
     }
     else {
 	G_important_message(_("Mapset switched. Your shell continues "
 			      "to use the history for the old mapset"));
     }
-    if (shell) {
-	if (strstr(shell, "tcsh")) {
-	    G_important_message(_("You can switch the history by commands:\n"
-				  "history -S; history -L %s/.history; setenv histfile=%s/.history"),
-				mapset_new_path, mapset_new_path);
-	}
-	else if (strstr(shell, "zsh")) {
-	    G_important_message(_("You can switch the history by commands:\n"
-				  "fc -W; fc -R %s/.zsh_history; HISTFILE=%s/.zsh_history"),
-				mapset_new_path, mapset_new_path);
-	}
+    if (shell && strstr(shell, "tcsh")) {
+	G_important_message(_("You can switch the history by commands:\n"
+			      "history -S; history -L %s/.history; setenv histfile=%s/.history"),
+			      mapset_new_path, mapset_new_path);
     }
 
     G_verbose_message(_("Your current mapset is <%s>"), mapset_new);

+ 7 - 1
lib/init/grass.py

@@ -1884,7 +1884,13 @@ def sh_like_startup(location, location_name, grass_env_file, sh):
     local z_lo=`g.gisenv get=LOCATION_NAME`
     local z_ms=`g.gisenv get=MAPSET`
     ZLOC="Mapset <$z_ms> in <$z_lo>"
-    """
+    if [ "$_grass_old_mapset" != "$MAPSET_PATH" ] ; then
+        fc -A -I
+        HISTFILE="$MAPSET_PATH/{sh_history}"
+        fc -R
+        _grass_old_mapset="$MAPSET_PATH"
+    fi
+    """.format(sh_history=sh_history)
     elif sh == "bash":
         # Append existing history to file ("flush").
         # Clear the (in-memory) history.