mirror of
https://github.com/ddworken/hishtory.git
synced 2025-08-19 03:06:45 +02:00
Run the command in the background for zsh
This commit is contained in:
@@ -839,6 +839,7 @@ echo foo`)
|
|||||||
|
|
||||||
// Test querying for all commands
|
// Test querying for all commands
|
||||||
waitForBackgroundSavesToComplete(t)
|
waitForBackgroundSavesToComplete(t)
|
||||||
|
time.Sleep(time.Second)
|
||||||
out = hishtoryQuery(t, tester, "")
|
out = hishtoryQuery(t, tester, "")
|
||||||
expected := []string{"echo foo", "ls /a"}
|
expected := []string{"echo foo", "ls /a"}
|
||||||
for _, item := range expected {
|
for _, item := range expected {
|
||||||
|
@@ -19,6 +19,5 @@ function _hishtory_precmd() {
|
|||||||
unset _hishtory_first_prompt
|
unset _hishtory_first_prompt
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
# TODO: Run this in the background
|
(hishtory saveHistoryEntry zsh $_hishtory_exit_code "$_hishtory_command" $_hishtory_start_time &)
|
||||||
hishtory saveHistoryEntry zsh $_hishtory_exit_code "$_hishtory_command" $_hishtory_start_time
|
|
||||||
}
|
}
|
||||||
|
@@ -43,6 +43,9 @@ var TestConfigShContents string
|
|||||||
//go:embed config.zsh
|
//go:embed config.zsh
|
||||||
var ConfigZshContents string
|
var ConfigZshContents string
|
||||||
|
|
||||||
|
//go:embed test_config.zsh
|
||||||
|
var TestConfigZshContents string
|
||||||
|
|
||||||
var Version string = "Unknown"
|
var Version string = "Unknown"
|
||||||
|
|
||||||
func getCwd() (string, error) {
|
func getCwd() (string, error) {
|
||||||
@@ -366,7 +369,11 @@ func Install() error {
|
|||||||
func configureZshrc(homedir, binaryPath string) error {
|
func configureZshrc(homedir, binaryPath string) error {
|
||||||
// Create the file we're going to source in our zshrc. Do this no matter what in case there are updates to it.
|
// Create the file we're going to source in our zshrc. Do this no matter what in case there are updates to it.
|
||||||
zshConfigPath := path.Join(homedir, shared.HISHTORY_PATH, "config.zsh")
|
zshConfigPath := path.Join(homedir, shared.HISHTORY_PATH, "config.zsh")
|
||||||
err := ioutil.WriteFile(zshConfigPath, []byte(ConfigZshContents), 0o644)
|
configContents := ConfigZshContents
|
||||||
|
if os.Getenv("HISHTORY_TEST") != "" {
|
||||||
|
configContents = TestConfigZshContents
|
||||||
|
}
|
||||||
|
err := ioutil.WriteFile(zshConfigPath, []byte(configContents), 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to write config.zsh file: %v", err)
|
return fmt.Errorf("failed to write config.zsh file: %v", err)
|
||||||
}
|
}
|
||||||
|
25
client/lib/test_config.zsh
Normal file
25
client/lib/test_config.zsh
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# This is the same as config.zsh, except it doesn't run the save process in the background. This is crucial to making tests reproducible.
|
||||||
|
|
||||||
|
autoload -U add-zsh-hook
|
||||||
|
add-zsh-hook zshaddhistory _hishtory_add
|
||||||
|
add-zsh-hook precmd _hishtory_precmd
|
||||||
|
|
||||||
|
_hishtory_first_prompt=1
|
||||||
|
|
||||||
|
function _hishtory_add() {
|
||||||
|
# Runs after <ENTER>, but before the command is executed
|
||||||
|
# $1 contains the command that was run
|
||||||
|
_hishtory_command=$1
|
||||||
|
_hishtory_start_time=`date +%s`
|
||||||
|
}
|
||||||
|
|
||||||
|
function _hishtory_precmd() {
|
||||||
|
# Runs after the command is executed in order to render the prompt
|
||||||
|
# $? contains the exit code (TODO: is this always true? Could other precmds break this?)
|
||||||
|
_hishtory_exit_code=$?
|
||||||
|
if [ -n "$_hishtory_first_prompt" ]; then
|
||||||
|
unset _hishtory_first_prompt
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
hishtory saveHistoryEntry zsh $_hishtory_exit_code "$_hishtory_command" $_hishtory_start_time
|
||||||
|
}
|
Reference in New Issue
Block a user