Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -g -O2 -Wno-parentheses -Wno-format-security uname output: Linux summerland 4.9.0-8-amd64 #1 SMP Debian 4.9.144-3.1 (2019-02-19) x86_64 GNU/Linux Machine Type: x86_64-pc-linux-gnu
Bash Version: 5.0 Patch Level: 3 Release Status: maint Description: Silence pushd/popd output if executed with -q. This could also be achieved by executing them with 2>/dev/null, but -q avoids the extra open(2).
--- a/builtins/pushd.def.orig +++ b/builtins/pushd.def @@ -1,7 +1,7 @@ This file is pushd.def, from which is created pushd.c. It implements the builtins "pushd", "popd", and "dirs" in Bash. -Copyright (C) 1987-2015 Free Software Foundation, Inc. +Copyright (C) 1987-2015, 2019 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -34,6 +34,8 @@ Options: -n Suppresses the normal change of directory when adding directories to the stack, so only the stack is manipulated. + -q Suppresses printing the directory stack after manipulation. + Arguments: +N Rotates the stack so that the Nth directory (counting from the left of the list shown by `dirs', starting with @@ -66,6 +68,8 @@ Options: -n Suppresses the normal change of directory when removing directories from the stack, so only the stack is manipulated. + -q Suppresses printing the directory stack after manipulation. + Arguments: +N Removes the Nth entry counting from the left of the list shown by `dirs', starting with zero. For example: `popd +0' @@ -168,6 +172,7 @@ static int get_dirstack_index __P((intmax_t, int, int *)); #define ROTATE 0x02 #define LONGFORM 0x04 #define CLEARSTAK 0x08 +#define QUIET 0x10 int pushd_builtin (list) @@ -218,6 +223,10 @@ pushd_builtin (list) { flags |= NOCD; } + else if (ISOPTION (list->word->word, 'q')) + { + flags |= QUIET; + } else if (ISOPTION (list->word->word, '-')) { list = list->next; @@ -300,7 +309,8 @@ pushd_builtin (list) if (j == EXECUTION_SUCCESS) { add_dirstack_element ((flags & NOCD) ? savestring (list->word->word) : current_directory); - dirs_builtin ((WORD_LIST *)NULL); + if ((flags & QUIET) == 0) + dirs_builtin ((WORD_LIST *)NULL); if (flags & NOCD) free (current_directory); return (EXECUTION_SUCCESS); @@ -334,6 +344,10 @@ popd_builtin (list) { flags |= NOCD; } + else if (ISOPTION (list->word->word, 'q')) + { + flags |= QUIET; + } else if (ISOPTION (list->word->word, '-')) { list = list->next; @@ -400,7 +414,8 @@ popd_builtin (list) pushd_directory_list[i] = pushd_directory_list[i + 1]; } - dirs_builtin ((WORD_LIST *)NULL); + if ((flags & QUIET) == 0) + dirs_builtin ((WORD_LIST *)NULL); return (EXECUTION_SUCCESS); }