-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any idea how to create the equivalent to "cd --" in powershell? #6
Comments
Hrm that's fun. I'll try this weekend.
…On Fri, 1 May 2020, 23:03 E:V:A, ***@***.***> wrote:
I found you great powershell aliases to get nix style back into PS.
I've been looking for a while, to find the fantastic equivalent to using cd
-- in linux/bash, to get the last visited directories.
$ cd --
0 /cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/lib/x64
1 /cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/lib
2 /cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2
3 /cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/tools
4 /cygdrive/d/avatarify/avatarify
5 /cygdrive/d/avatarify
6 /cygdrive/d
7 ~
Then you can just do cd -4 to go there.
I use this 100 times a day, even under Cygwin, but I can't find anything
like it in Windows powershell. The closest info is here
<https://docs.microsoft.com/en-us/powershell/scripting/samples/managing-current-location?view=powershell-7#saving-and-recalling-recent-locations-push-location-and-pop-location>
.
Any ideas how to implement this?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#6>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABKEMUUA2FJ6NCFYNKRULLRPNBLBANCNFSM4MXMSRMA>
.
|
Also if you want to try, you'd made a cd function that stored the new
directories in an array. When someone does a --, you pop the last item off
the end of the array.
…On Fri, 1 May 2020, 23:03 E:V:A, ***@***.***> wrote:
I found you great powershell aliases to get nix style back into PS.
I've been looking for a while, to find the fantastic equivalent to using cd
-- in linux/bash, to get the last visited directories.
$ cd --
0 /cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/lib/x64
1 /cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/lib
2 /cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2
3 /cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/tools
4 /cygdrive/d/avatarify/avatarify
5 /cygdrive/d/avatarify
6 /cygdrive/d
7 ~
Then you can just do cd -4 to go there.
I use this 100 times a day, even under Cygwin, but I can't find anything
like it in Windows powershell. The closest info is here
<https://docs.microsoft.com/en-us/powershell/scripting/samples/managing-current-location?view=powershell-7#saving-and-recalling-recent-locations-push-location-and-pop-location>
.
Any ideas how to implement this?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#6>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABKEMUUA2FJ6NCFYNKRULLRPNBLBANCNFSM4MXMSRMA>
.
|
I just found this: But it doesn't quite get there, although smart. (I like numbered lists) |
Hmm, here's the bashrc function: #----------------------------------------------------------
# b) function cd_func
#----------------------------------------------------------
# This function defines a 'cd' replacement function capable of keeping,
# displaying and accessing history of visited directories, up to 10 entries.
# To use it, uncomment it, source this file and try 'cd --'.
# acd_func 1.0.5, 10-nov-2004
# Petar Marinov, http:/geocities.com/h2428, this is public domain
#----------------------------------------------------------
cd_func ()
{
local x2 the_new_dir adir index
local -i cnt
if [[ $1 == "--" ]]; then
dirs -v
return 0
fi
the_new_dir=$1
[[ -z $1 ]] && the_new_dir=$HOME
if [[ ${the_new_dir:0:1} == '-' ]]; then
#
# Extract dir N from dirs
index=${the_new_dir:1}
[[ -z $index ]] && index=1
adir=$(dirs +$index)
[[ -z $adir ]] && return 1
the_new_dir=$adir
fi
#
# '~' has to be substituted by ${HOME}
[[ ${the_new_dir:0:1} == '~' ]] && the_new_dir="${HOME}${the_new_dir:1}"
#
# Now change to the new dir and add to the top of the stack
pushd "${the_new_dir}" > /dev/null
[[ $? -ne 0 ]] && return 1
the_new_dir=$(pwd)
#
# Trim down everything beyond 11th entry
popd -n +11 2>/dev/null 1>/dev/null
#
# Remove any other occurence of this dir, skipping the top of the stack
for ((cnt=1; cnt <= 10; cnt++)); do
x2=$(dirs +${cnt} 2>/dev/null)
[[ $? -ne 0 ]] && return 0
[[ ${x2:0:1} == '~' ]] && x2="${HOME}${x2:1}"
if [[ "${x2}" == "${the_new_dir}" ]]; then
popd -n +$cnt 2>/dev/null 1>/dev/null
cnt=cnt-1
fi
done
return 0
}
alias cd=cd_func |
Unfortunately I suck at anything powershell, and whatever I get done, is only through pure, sheer, iron, will-power, so it take me ages! (Improving though.) |
any updates or ideas? |
Following the links above, it seem that this commandlet is getting very close to that idea. however, it required two files where |
I found you great powershell aliases to get nix style back into PS.
I've been looking for a while, to find the fantastic equivalent to using
cd --
in linux/bash, to get the last visited directories.Then you can just do
cd -4
to go there.I use this 100 times a day, even under Cygwin, but I can't find anything like it in Windows powershell. The closest info is here.
Any ideas how to implement this?
The text was updated successfully, but these errors were encountered: