patchGNU Octave - Patches: patch #8139, cd: Add Bash-like "cd -"...


patch #8139: cd: Add Bash-like "cd -" shortcut to change to last dir from input prompt.

Submitter:  Philipp Kutin <pkutin>
Submitted:  Tue 30 Jul 2013 09:09:41 PM UTC
Category:  Core : new feature Priority:  3 - Low
Status:  Postponed Privacy:  Public
Assigned to:  None Open/Closed:  Open
* Mandatory Fields

Add a New Comment Rich Markup

Fri 08 Nov 2013 12:48:11 PM UTC, comment #3: 

Attached is a second patch that can be applied on a recent Octave HG and incorporating Mike's suggestions:

  • "cd -" works everywhere
  • shorter error message

(file #29572)

Philipp Kutin <pkutin>
Fri 18 Oct 2013 01:45:38 PM UTC, comment #2: 

I merely did it that way for minimality's sake -- so that there's no change of the API and programmatic use of 'cd' will continue to function as before. But I didn't succeed very well, as the cases where '-' is effective (script, etc.) show. So I guess going with always invoking that special behavior is OK.

Agreed about the message, it's short and to the point.

Philipp Kutin <pkutin>
Fri 18 Oct 2013 02:48:28 AM UTC, comment #1: 

Is there a reason for only wanting to do this at the top execution level? In the unix shell it is perfectly legal to do "cd -" inside of a script or a subshell.

I agree it's probably unlikely that anyone names a directory "-", but it is something to consider.

I like the idea, as long as no one else is worried about potentially breaking compatibility with directories named "-".

I'd prefer something like "cd: no previous directory" as the error message.

Mike Miller <mtmiller>
Group Member
Tue 30 Jul 2013 09:09:41 PM UTC, original submission:  
  • libinterp/corefcn/ When issuing "cd" from the top level, save

  current working dir before the change. When doing "cd -", change to that
  one. Caveat: works in a little more contexts than just from the prompt.
  (For example, anon. function defined at top level that does "cd", script
  called from top level.)


This is useful when you're working in a directory with code, but temporarily want to load some data. You'd "cd" into that directory, but to return to the first one, don't need to enter it on the command line (which is inconvenient, as the completion doesn't behave properly when the partial path has more than one component.)

The idea is to make it work only when issued from the input prompt. However, the closest I found is symbol_table::at_top_level(), which presumably embodies the "workspace" concept. So, "cd -" also changes to the last WD in e.g. M-scripts called from the top level, which may not be desirable. (But then again, it's unlikely to be practically relevant -- who would call their directory "-"?)

Philipp Kutin <pkutin>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Attached Files
file #29572:  cd-bashlike-dash-pk-2.patch added by pkutin (2KiB - text/x-patch)
file #28714:  cd-bashlike-dash-pk.patch added by pkutin (2KiB - text/x-patch)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by siko1056 (Updated the item)
  • -email is unavailable- added by pkutin (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.


    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-01-25 mtmiller Carbon-CopyRemoved 80942 -
    2020-01-18 siko1056 CategoryNone Core : new feature
        Priority5 - Normal 3 - Low
        StatusNeed Info Postponed
    2013-11-08 pkutin Attached File- Added cd-bashlike-dash-pk-2.patch, #29572
    2013-10-18 mtmiller StatusNone Need Info
    2013-07-30 pkutin Attached File- Added cd-bashlike-dash-pk.patch, #28714

    Back to the top

    Powered by Savane 3.13-c54d.
    Corresponding source code