Skip to content

Add support for 'cd -' #2188

Closed
Closed

Description

@SRGOM

Sorely missing the ability of being able to go to previous directory without any previous action.

Activity

  1. added
    Issue-Enhancement
    WG-Cmdlets
    on Sep 5, 2016
  2. vors commented on Sep 5, 2016

    @vors
    Collaborator

    Good point! We probably should add cd - syntax at the same time.

  3. rkeithhill commented on Sep 5, 2016

    @rkeithhill
    Collaborator

    S (@SRGOM) For now you can use Push-Location (alias pushd) and Pop-Location (alias popd).

  4. rkeithhill commented on Sep 5, 2016

    @rkeithhill
    Collaborator

    sergei (@vors) if you're going to do that then go all the way and implement a directory history stack e.g.:

    13> cd
    
         # Directory Stack:
       --- ----------------
         0 C:\Users\Keith
         1 C:\Users\Keith\GitHub\PowerShell\Plaster
         2 C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices
         3 C:\Users\Keith\GitHub\rkeithhill\vscode-powershell
         4 C:\Users\Keith\GitHub\rkeithhill\vscode-powershell\scripts
         5 C:\Users\Keith\GitHub\rkeithhill\vscode-powershell
    ->   6 C:\Users\Keith\GitHub\rkeithhill
    
    ~\GitHub\RKEITHHILL
    14> cd -
    ~\GitHub\rkeithhill\vscode-powershell
    15> cd -
    ~\GitHub\rkeithhill\vscode-powershell\scripts
    16> cd +
    ~\GitHub\rkeithhill\vscode-powershell
    17> cd -1
    ~\GitHub\PowerShell\Plaster
    18> cd $profile
    ~\Documents\WindowsPowerShell
    19> cd c:\program files
    C:\program files
    

    See https://github.com/Pscx/Pscx/blob/master/Src/Pscx/Modules/CD/Pscx.CD.psm1

  5. vors commented on Sep 5, 2016

    @vors
    Collaborator

    Keith Hill (@rkeithhill) cd - actually was part of #1083 (comment)

    Is this history stack used in other shells?

  6. rkeithhill commented on Sep 5, 2016

    @rkeithhill
    Collaborator

    sergei (@vors) Take Command supports this: https://jpsoft.com/help/index.htm?cd.htm

    In fact, you will probably find several PowerShell modules that implement CD history in different ways. The one above is from PSCX. I've seen other modules that retain history and use fuzzy matching to find the directory with auto-completion as you type IIRC. There's likely enough variation here that this functionality is best implemented by 3rd party modules.

  7. vors commented on Sep 5, 2016

    @vors
    Collaborator

    That's what I think. There are a lot of approaches for advanced usage and they are implemented or could be implemented as additional modules. Core functionality should be conservative and universal. PowerShell team agreed that cd - should be included in the core cd, but that's probably where we stop.

  8. Jaykul commented on Sep 5, 2016

    @Jaykul
    Contributor

    I'm a bit confused. If cd - is in the core cd, doesn't that make cd into pushd and popd?

    Or perhaps I should say: maybe you should implement cd as a function which calls pushd (or popd).

  9. vors commented on Sep 6, 2016

    @vors
    Collaborator

    If cd - is in the core cd, doesn't that make cd into pushd and popd?

    No, because it will only keep knowledge about 1 previous location. And this location could be $env:OLDPWD which would address the original issue described by S (@SRGOM)

  10. SRGOM commented on Sep 6, 2016

    @SRGOM
    ContributorAuthor

    I should note that I wouldn't want this to be specific to OS-Linux, although yes such a functionality isn't present in Windows already.

    Look at http://linux.die.net/man/1/zshoptions if you want to know what all options zsh has. A lot of us use a lot of options over there.

    I would love to use an actual programming language with a clean syntax as my shell but I will not give up the ease of access that comes with bash/zsh. I will list a few power tools/options that come to my mind that are absolutely indispensable to me and the power users I know.

    1. History, big deal for most. I have this setopt histfindnodups histignoredups histignorespace. I want to be able to search through it, and very quickly

    2. Moving around- I use github:rupa/z which is a fuzzy matcher. You think you can show a navigable dropdown in fuzzy cd mode? Maybe call it zd? z doesn't have a dropdown but its still very cool

    3. Completion/editing - one area where I feel PSReadLine is lacking compared to bash/zsh. (Or maybe I don't know enough? Please correct me). Can't do Ctrl-X Ctrl-E (edit command in EDITOR), Alt-s, cycle through completions in bash or just repeated tabs in zsh.

    TBC- I don't want PoSh to grow haphazardly like bash/zsh which are really pathetic for anything but interactive use. I also love the long-names, it makes my history so much better to read. But it's just very lacking for interactive use.

    I hope you guys incorporate features from zsh while keeping Powershell consistent and solid.

  11. vors commented on Sep 6, 2016

    @vors
    Collaborator

    Thank you for the thoughtful feedback!

    Yes, definitely not only on unix. We would like to keep the experience as close as it possible on all platforms.

    Absolutely agree about history. In fact, the very first PS code that I wrote was https://github.com/vors/PersistentHistory (yes, PowerShell didn't have persistent history built-in, kind of crazy). Meanwhile, PSReadLine was included in the out-of-the-box package and it addressed a lot of interactive usage issues, including history.
    I.e. histfindnodups histignoredups == Set-PSReadlineOption -HistoryNoDuplicates.
    Ctrl-X Ctrl-E is probably not in the standard keybindings, but can be added with Set-PSReadlineKeyHandler

    For moving around, there are projects inspired by autojump and z.sh

    https://github.com/tkellogg/Jump-Location
    https://github.com/vors/ZLocation

    They haven't been ported to Unix yet, but ZLocation probably would be at some point.
    Also, as Keith Hill (@rkeithhill) mentioned, PSCX has a replacement for cd. The point here is: there are a lot of different approaches about moving around and I don't think that we should pick THE ONE to be included in the core. They are already implemented (or could be implemented) as 3rd party modules.
    Meanwhile, cerating things (like cd -) could and probably should be included in the out-of-the-box expirience, because it's well established and expected in unix shells.

  12. SRGOM commented on Sep 6, 2016

    @SRGOM
    ContributorAuthor

    Thanks for your reply, sergei (@vors). I agree about a careful boundary about what should be in powershell and what should be outside. I do think that certain useful functionality should be added-on by default using external packages, PS-Readline itself being a great example.

  13. SRGOM commented on Sep 11, 2016

    @SRGOM
    ContributorAuthor

    I think I agree about the history part btw- it doesn't belong in Powershell itself (just like a lot of things don't). I'm right now on Linux and not liking how zsh/bash handle history order and timestamps(love everything else history-related). Maybe there's a need to stop and think about the right way of doing things.

  14. added
    Up-for-Grabs
    on Nov 1, 2016
  15. Bill-Stewart commented on Jan 31, 2017

    @Bill-Stewart

    If we are talking about a location history (like command history, except locations only), then yes please.

  16. added
    Hacktoberfest
    on Oct 1, 2017
  17. bergmeister commented on May 26, 2018

    @bergmeister
    Contributor

    Ilya (@iSazonov) Can you please rename the issue title to reflect its current state better. Something like Add support for 'cd -'?

  18. changed the title [-]Set-Location should set $env:OLDPWD[/-] [+]Add support for 'cd -'[/+] on May 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    HacktoberfestIssue-EnhancementResolution-FixedUp-for-GrabsWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions