1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
--- execute_cmd.c.orig 2014-03-02 13:15:12.000000000 -0500
+++ execute_cmd.c 2014-03-02 13:17:14.000000000 -0500
@@ -199,6 +199,9 @@
static int execute_intern_function __P((WORD_DESC *, FUNCTION_DEF *));
+/* 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;
@@ -4111,6 +4114,20 @@
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
set builtin_is_special. If this is a function or builtin, and we
--- builtins/shopt.def.orig 2014-03-02 13:18:07.000000000 -0500
+++ builtins/shopt.def 2014-03-02 13:19:22.000000000 -0500
@@ -83,6 +83,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;
extern int check_jobs_at_exit;
@@ -192,6 +193,7 @@
{ "hostcomplete", &perform_hostname_completion, shopt_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 },
{ "lastpipe", &lastpipe_opt, (shopt_set_func_t *)NULL },
#if defined (HISTORY)
@@ -305,6 +307,7 @@
cdable_vars = mail_warning = 0;
no_exit_on_failed_exec = print_shift_error = 0;
check_hashed_filenames = cdspelling = expand_aliases = 0;
+ implicitcd = 0;
source_uses_path = promptvars = 1;
--- doc/bash.1.orig 2014-03-02 13:19:59.000000000 -0500
+++ doc/bash.1 2014-03-02 13:21:10.000000000 -0500
@@ -9480,6 +9480,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 2014-03-02 13:21:54.000000000 -0500
+++ doc/bashref.texi 2014-03-02 13:22:31.000000000 -0500
@@ -5118,6 +5118,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
|