about summary refs log tree commit diff stats
path: root/xxxterm.c
diff options
context:
space:
mode:
authorMarco Peereboom <marco@conformal.com>2011-01-14 18:57:31 +0000
committerMarco Peereboom <marco@conformal.com>2011-01-14 18:57:31 +0000
commit02a0f2685b140bccab67bac892a95e76925d5733 (patch)
tree6e0e8964799faeb81916833e90683c0b6bc2b1c8 /xxxterm.c
parent15c5b7db71cc4d1e8d63245f1bc4ecd673c19fa6 (diff)
downloadxombrero-02a0f2685b140bccab67bac892a95e76925d5733.tar.gz
make :w write the current session
make :session open moo clsoe the current open tabs, it is a sesion you know
Diffstat (limited to 'xxxterm.c')
-rw-r--r--xxxterm.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/xxxterm.c b/xxxterm.c
index daad2be..3f05ffc 100644
--- a/xxxterm.c
+++ b/xxxterm.c
@@ -382,6 +382,9 @@ struct karg {
 #define XT_CMD_TABNEW		(2)
 #define XT_CMD_TABNEW_CURRENT	(3)
 
+#define XT_SES_DONOTHING	(0)
+#define XT_SES_CLOSETABS	(1)
+
 /* mime types */
 struct mime_type {
 	char			*mt_type;
@@ -1511,6 +1514,7 @@ open_tabs(struct tab *t, struct karg *a)
 	FILE		*f = NULL;
 	char		*uri = NULL;
 	int		rv = 1;
+	struct tab	*ti, *tt;
 
 	if (a == NULL)
 		goto done;
@@ -1520,6 +1524,8 @@ open_tabs(struct tab *t, struct karg *a)
 	if ((f = fopen(file, "r")) == NULL)
 		goto done;
 
+	ti = TAILQ_LAST(&tabs, tab_list);
+
 	for (;;) {
 		if ((uri = fparseln(f, NULL, NULL, NULL, 0)) == NULL)
 			if (feof(f) || ferror(f))
@@ -1532,6 +1538,19 @@ open_tabs(struct tab *t, struct karg *a)
 		uri = NULL;
 	}
 
+	/* close open tabs */
+	if (a->i == XT_SES_CLOSETABS && ti != NULL) {
+		for (;;) {
+			tt = TAILQ_FIRST(&tabs);
+			if (tt != ti) {
+				delete_tab(tt);
+				continue;
+			}
+			delete_tab(tt);
+			break;
+		}
+	}
+
 	rv = 0;
 done:
 	if (f)
@@ -1558,6 +1577,7 @@ restore_saved_tabs(void)
 		a.s = XT_RESTART_TABS_FILE;
 	}
 
+	a.i = XT_SES_DONOTHING;
 	rv = open_tabs(NULL, &a);
 
 	if (unlink_file)
@@ -1578,10 +1598,11 @@ save_tabs(struct tab *t, struct karg *a)
 	if (a == NULL)
 		return (1);
 	if (a->s == NULL)
-		return (1);
-
-	snprintf(file, sizeof file, "%s/%s", sessions_dir, a->s);
-
+		snprintf(file, sizeof file, "%s/%s",
+		    sessions_dir, named_session);
+	else
+		snprintf(file, sizeof file, "%s/%s", sessions_dir, a->s);
+warnx("save_tabs: %s", file);
 	if ((f = fopen(file, "w")) == NULL) {
 		show_oops(t, "Can't open save_tabs file: %s", strerror(errno));
 		return (1);
@@ -1604,7 +1625,7 @@ save_tabs_and_quit(struct tab *t, struct karg *args)
 {
 	struct karg		a;
 
-	a.s = XT_SAVED_TABS_FILE;
+	a.s = NULL;
 	save_tabs(t, &a);
 	quit(t, NULL);
 
@@ -3827,6 +3848,7 @@ session_open(struct tab *t, char *filename, char **ret)
 		goto done;
 
 	a.s = f;
+	a.i = XT_SES_CLOSETABS;
 	open_tabs(t, &a);
 	strlcpy(named_session, f, sizeof named_session);
 
@@ -4024,9 +4046,9 @@ struct cmd {
 	{ "q!",			0,	quit,			{0} },
 	{ "qa",			0,	quit,			{0} },
 	{ "qa!",		0,	quit,			{0} },
-	{ "w",			0,	save_tabs,		{.s = XT_SAVED_TABS_FILE} },
-	{ "wq",			0,	save_tabs_and_quit,	{.s = XT_SAVED_TABS_FILE} },
-	{ "wq!",		0,	save_tabs_and_quit,	{.s = XT_SAVED_TABS_FILE} },
+	{ "w",			0,	save_tabs,		{0} },
+	{ "wq",			0,	save_tabs_and_quit,	{0} },
+	{ "wq!",		0,	save_tabs_and_quit,	{0} },
 	{ "help",		0,	help,			{0} },
 	{ "about",		0,	about,			{0} },
 	{ "stats",		0,	stats,			{0} },
@@ -6683,6 +6705,7 @@ main(int argc, char *argv[])
 		restore_saved_tabs();
 	else {
 		a.s = named_session;
+		a.i = XT_SES_DONOTHING;
 		open_tabs(NULL, &a);
 	}