freebsd-ports/shells/bash3/files/xpatch-implicitcd

99 lines
3.5 KiB
Text

#
# new shopt `implicitcd'
# http://lists.gnu.org/archive/html/bug-bash/2004-09/msg00024.html
#
--- execute_cmd.c.orig Sat Nov 5 17:37:21 2005
+++ execute_cmd.c Wed Dec 28 19:38:09 2005
@@ -190,6 +190,9 @@
/* The line number that the currently executing function starts on. */
static int function_line_number;
+/* add an implicit `cd' if the command is the name of a directory */
+int implicitcd = 0;
+
/* Set to 1 if fd 0 was the subject of redirection to a subshell. Global
so that reader_loop can set it to zero before executing a command. */
int stdin_redir;
@@ -2913,6 +2916,20 @@
this_command_name = words->word->word;
QUIT;
+
+ if (implicitcd && interactive_shell && words->next == NULL && func == 0 && builtin == 0)
+ {
+ struct stat finfo;
+
+ if ((stat (words->word->word, &finfo) == 0) && (S_ISDIR (finfo.st_mode)))
+ {
+ this_command_name = "cd";
+ last_shell_builtin = this_shell_builtin;
+ this_shell_builtin = builtin_address (this_command_name);
+ result = (*this_shell_builtin) (words);
+ goto return_result;
+ }
+ }
/* This command could be a shell builtin or a user-defined function.
We have already found special builtins by this time, so we do not
--- builtins/shopt.def.orig Sat Feb 19 19:25:03 2005
+++ builtins/shopt.def Wed Dec 28 19:38:09 2005
@@ -66,6 +66,7 @@
extern int check_window_size;
extern int glob_ignore_case, match_ignore_case;
extern int hup_on_exit;
+extern int implicitcd;
extern int xpg_echo;
extern int gnu_error_format;
@@ -145,6 +146,7 @@
{ "hostcomplete", &perform_hostname_completion, enable_hostname_completion },
#endif
{ "huponexit", &hup_on_exit, (shopt_set_func_t *)NULL },
+ { "implicitcd", &implicitcd, (shopt_set_func_t *)NULL },
{ "interactive_comments", &interactive_comments, set_shellopts_after_change },
#if defined (HISTORY)
{ "lithist", &literal_history, (shopt_set_func_t *)NULL },
@@ -253,6 +255,7 @@
cdable_vars = mail_warning = 0;
no_exit_on_failed_exec = print_shift_error = 0;
check_hashed_filenames = cdspelling = expand_aliases = check_window_size = 0;
+ implicitcd = 0;
source_uses_path = promptvars = 1;
--- doc/bash.1.orig Wed Oct 12 12:40:52 2005
+++ doc/bash.1 Wed Dec 28 19:38:09 2005
@@ -8090,6 +8090,15 @@
.B SIGHUP
to all jobs when an interactive login shell exits.
.TP 8
+.B implicitcd
+If this is set, a directory name typed as a command is treated as a
+request to change to that directory.
+This behavior is inhibited in non-interactive mode or for command
+strings with more than one word.
+Changing directory takes precedence over executing a like-named
+command, but it is done after alias substitutions.
+Tilde and variable expansions work as expected.
+.TP 8
.B interactive_comments
If set, allow a word beginning with
.B #
--- doc/bashref.texi.orig Mon Oct 3 16:07:21 2005
+++ doc/bashref.texi Wed Dec 28 19:38:09 2005
@@ -3697,6 +3697,15 @@
If set, Bash will send @code{SIGHUP} to all jobs when an interactive
login shell exits (@pxref{Signals}).
+@item implicitcd
+If this is set, a directory name typed as a command is treated as a
+request to change to that directory.
+This behavior is inhibited in non-interactive mode or for command
+strings with more than one word.
+Changing directory takes precedence over executing a like-named
+command, but it is done after alias substitutions.
+Tilde and variable expansions work as expected.
+
@item interactive_comments
Allow a word beginning with @samp{#}
to cause that word and all remaining characters on that