[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[50 character or so descriptive subject here (for reference)]
From: |
ggopalak |
Subject: |
[50 character or so descriptive subject here (for reference)] |
Date: |
Sun, 21 Sep 2003 22:19:31 +1000 (EST) |
Configuration Information [Automatically generated, do not change]:
Machine: sparc
OS: solaris2.8
Compiler: cc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='sparc'
-DCONF_OSTYPE='solaris2.8' -DCONF_MACHTYPE='sparc-sun-solaris2.8'
-DCONF_VENDOR='sun' -DSHELL -DHAVE_CONFIG_H -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -I. -I. -I./include -I./lib
-I/usr/local/include -g
uname output: SunOS numbat.cs.rmit.edu.au 5.8 Generic_108528-23 sun4u sparc
SUNW,Ultra-80
Machine Type: sparc-sun-solaris2.8
Bash Version: 2.04
Patch Level: 0
Release Status: release
Description:
This is a feature I like in ksh. Running 'cd' with two parameters will
cause all instances of the first string to be replaced in 'pwd' with
the second string, and then a 'cd' done.
Repeat-By:
None
Fix:
diff -rbc bash-2.05b/builtins/cd.def bash/builtins/cd.def
*** bash-2.05b/builtins/cd.def Tue Jul 16 04:51:39 2002
--- bash/builtins/cd.def Sun Sep 21 21:31:21 2003
***************
*** 177,182 ****
--- 177,231 ----
lflag = (cdable_vars ? LCD_DOVARS : 0) |
((interactive && cdspelling) ? LCD_DOSPELL : 0);
+ /* `cd' with two arguments replaces all occurrences of the
+ first arg in `pwd' with the second arg and then
+ does a `cd' with the resulting string */
+ if (list && list->next)
+ {
+ char *tmp = NULL, *pwd = NULL;
+ char *pwd_save = NULL, *newdir = NULL;
+ char *first = list->word->word;
+ char *second = list->next->word->word;
+ int length_f, length_s, length;
+
+ #define tcwd the_current_working_directory
+
+ pwd = tcwd ? (no_symlinks ? sh_physpath (tcwd, 0) : tcwd)
+ : get_working_directory ("pwd");
+ #undef tcwd
+ if (pwd == 0)
+ {
+ builtin_error ("Unable to determine current directory");
+ return (EXECUTION_FAILURE);
+ }
+ pwd_save = xmalloc(strlen(pwd) + 1);
+ strcpy(pwd_save, pwd);
+ pwd = pwd_save;
+
+ /* Just for xrealloc to work */
+ newdir = xmalloc(1);
+ newdir[0] = '\0';
+
+ length_f = strlen(first);
+ length_s = strlen(second);
+ length = 1;
+ while ((tmp = strstr (pwd, first)) != 0)
+ {
+ /* No need to add 1 */
+ length += (tmp - pwd) + length_s;
+ newdir = xrealloc (newdir, length);
+ *tmp = '\0';
+ strcat (newdir, pwd);
+ strcat (newdir, second);
+ pwd = tmp + length_f;
+ }
+ newdir = xrealloc (newdir, length + strlen(pwd));
+ strcat (newdir, pwd);
+ free (list->word->word);
+ list->word->word = newdir;
+ free (pwd_save);
+ }
+
if (list == 0)
{
/* `cd' without arguments is equivalent to `cd $HOME' */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [50 character or so descriptive subject here (for reference)],
ggopalak <=