forked from version-fox/vfox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(terminal type): add clink mode terminal
add clink injected cmd.exe terminal support
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2024 Han Li and contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package shell | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/version-fox/vfox/internal/env" | ||
) | ||
|
||
const clinkHook = ` | ||
{{.EnvContent}} | ||
"{{.SelfPath}}" env --cleanup > nul 2> nul | ||
` | ||
|
||
type clink struct{} | ||
|
||
var Clink = clink{} | ||
|
||
func (b clink) Activate() (string, error) { | ||
return clinkHook, nil | ||
} | ||
|
||
func (b clink) Export(envs env.Vars) (out string) { | ||
for key, value := range envs { | ||
if value == nil { | ||
out += b.set(key, "") | ||
} else { | ||
out += b.set(key, *value) | ||
} | ||
} | ||
return | ||
} | ||
|
||
func (b clink) set(key, value string) string { | ||
return fmt.Sprintf("set \"%s=%s\"\n", key, value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Find the clink script path: `clink info | findstr scripts` | ||
|
||
Generate `vfox.cmd` script to clink script path | ||
```bat | ||
where /q vfox && for /f "tokens=*" %%i in ('vfox activate clink') do call %%i | ||
``` | ||
|
||
Generate `vfox.lua` script to clink script path | ||
```lua | ||
os.setenv('__VFOX_PID', os.getpid()) | ||
local vfox_prompt = clink.promptfilter(30) | ||
function vfox_prompt:filter(prompt) | ||
local env = io.popen('vfox env -s clink') | ||
for line in env:lines() do | ||
local ei = string.find(line, '=') | ||
if ei and ei > 1 then | ||
local key = string.sub(line, 6, ei-1) | ||
local val = string.sub(line, ei+1, #line-1) | ||
--print('['.. key ..']','['.. val ..']') | ||
os.setenv(key, val ~= '' and val or nil) | ||
end | ||
end | ||
env:close() | ||
end | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters