diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 741a72d..bbc8c0e 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -1087,26 +1087,19 @@ exec_command(const char *cmd,
 	{
 		char	   *fname = psql_scan_slash_option(scan_state,
 												   OT_NORMAL, NULL, true);
-
-#if defined(WIN32) && !defined(__CYGWIN__)
-
-		/*
-		 * XXX This does not work for all terminal environments or for output
-		 * containing non-ASCII characters; see comments in simple_prompt().
-		 */
-#define DEVTTY	"con"
-#else
-#define DEVTTY	"/dev/tty"
-#endif
-
 		expand_tilde(&fname);
-		/* This scrolls off the screen when using /dev/tty */
-		success = saveHistory(fname ? fname : DEVTTY, -1, false, false);
-		if (success && !pset.quiet && fname)
-			printf(_("Wrote history to file \"%s\".\n"), fname);
-		if (!fname)
-			putchar('\n');
-		free(fname);
+		if (fname)
+		{
+			success = saveHistory(fname, -1, false, false);
+			if (success && !pset.quiet && fname)
+				printf(_("Wrote history to file \"%s\".\n"), fname);
+			free(fname);
+		}
+		else
+		{
+			/* print history to term, this needs no arguments and will use pager if applicable */
+			success = printHistory(pset.popt.topt.pager);
+		}
 	}
 
 	/* \set -- generalized set variable/option command */
diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c
index aa32a3f..6d0b8d9 100644
--- a/src/bin/psql/input.c
+++ b/src/bin/psql/input.c
@@ -412,6 +412,36 @@ saveHistory(char *fname, int max_lines, bool appendFlag, bool encodeFlag)
 }
 
 
+/*
+ * Prints the history when/the user runs \s command without any file arguments.
+ */
+bool
+printHistory(unsigned short int pager)
+{
+#ifdef USE_READLINE
+	FILE *output;
+	int i;
+	HIST_ENTRY *curr;
+	/* on mac osx readline is actually just a compatibilty layer around
+	   the bsd libedit, on linux we have proper readline. in both cases
+	   readline support is available if configure said so. we need to iterate
+	   over the history here and print it out, this is done using the below
+	   loop, which works on both readline and libedit. the other history
+	   iteration used in this file seems not to work with libedit and returns
+	   only the first history item. */
+	output = PageOutput(103, pager);
+	for (i = 1; (curr = history_get(i));i++) {
+		fprintf(output, "%s\n", curr->line);
+	}
+	ClosePager(output);
+	return true;
+#else
+	psql_error("history is not supported by this installation\n");
+	return false;
+#endif
+}
+
+
 static void
 finishInput(void)
 {
diff --git a/src/bin/psql/input.h b/src/bin/psql/input.h
index 1d10a22..a686ce3 100644
--- a/src/bin/psql/input.h
+++ b/src/bin/psql/input.h
@@ -43,6 +43,7 @@ char	   *gets_fromFile(FILE *source);
 
 void		initializeInput(int flags);
 bool		saveHistory(char *fname, int max_lines, bool appendFlag, bool encodeFlag);
+bool		printHistory(unsigned short int pager);
 
 void		pg_append_history(const char *s, PQExpBuffer history_buf);
 void		pg_send_history(PQExpBuffer history_buf);
