Skip to content

Commit

Permalink
shell cd hook init
Browse files Browse the repository at this point in the history
  • Loading branch information
moqsien committed Jun 25, 2024
1 parent b391dc2 commit 757bef4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
10 changes: 7 additions & 3 deletions internal/shell/sh/fish.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ https://fishshell.com/docs/current/cmds/function.html
Run this function when the variable VARIABLE_NAME changes value. Note that fish makes no guarantees on any particular timing or even that the function will be run for every single set. Rather it will be run when the variable has been set at least once, possibly skipping some values or being run when the variable has been set to the same value (except for universal variables set in other shells - only changes in the value will be picked up for those).
*/
const vmEnvFish = `# cd hook start
fish_add_path --global %s
function _vmr_cdhook --on-variable="PWD" --description "version manager cd hook"
if type -q vmr
vmr use -E
end
end
# cd hook end
fish_add_path --global %s
`
if set -q "$VMR_CD_INIT"
set VMR_CD_INIT "vmr_cd_init"
cd "$(pwd)"
end
# cd hook end`

/*
internal/terminal/terminal.go line:90
Expand Down
9 changes: 7 additions & 2 deletions internal/shell/sh/zsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ In cdhook, it will cd to the target directory and then try to execute "vmr use -
The command "vmr use -E" will automatically find the .vmr.lock file, and add corresponding versions of an SDK to the envs.
*/
const vmEnvZsh = `# cd hook start
export PATH=%s:$PATH
if [ -z "$(alias|grep cdhook)" ]; then
cdhook() {
if [ $# -eq 0 ]; then
Expand All @@ -27,9 +29,12 @@ if [ -z "$(alias|grep cdhook)" ]; then
}
alias cd='cdhook'
fi
# cd hook end
export PATH=%s:$PATH`
if [ ! $VMR_CD_INIT ]; then
VMR_CD_INIT="vmr_cd_init"
cd "$(pwd)"
fi
# cd hook end`

/*
internal/terminal/terminal.go line:90
Expand Down
12 changes: 10 additions & 2 deletions internal/shell/win.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const (
)

// PowershellHook for Powershell
const PowershellHook string = `function cdhook {
const PowershellHook string = `# cd hook start
function cdhook {
$TRUE_FALSE=(Test-Path $args[0])
if ( $TRUE_FALSE -eq "True" )
{
Expand All @@ -32,12 +33,19 @@ const PowershellHook string = `function cdhook {
}
}
if ( "" -ne $VMR_CD_INIT )
{
$VMR_CD_INIT="vmr_cd_init"
cd "$(-split $(pwd))"
}
function vmrsource {
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
}
Set-Alias -Name cd -Option AllScope -Value cdhook
Set-Alias -Name source -Value vmrsource`
Set-Alias -Name source -Value vmrsource
# cd hook end`

var _ Sheller = (*Shell)(nil)

Expand Down

0 comments on commit 757bef4

Please sign in to comment.