mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-20 03:47:54 +02:00
Fix bug with automatic cd-ing where quoting the directory caused tildes to not get expanded into the user's homedir
This commit is contained in:
parent
eaccc7b638
commit
19b9f67724
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
@ -390,7 +391,15 @@ func (m model) View() string {
|
||||
SELECTED_COMMAND = m.tableEntries[m.table.Cursor()].Command
|
||||
if m.selected == SelectedWithChangeDir {
|
||||
changeDir := m.tableEntries[m.table.Cursor()].CurrentWorkingDirectory
|
||||
// TODO: There is a bug here if changeDir contains ~, see https://askubuntu.com/questions/1032370/why-cant-i-cd-to-a-quoted-tilde
|
||||
if strings.HasPrefix(changeDir, "~/") {
|
||||
homedir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
hctx.GetLogger().Infof("UserHomeDir() return err=%v, skipping replacing ~/", err)
|
||||
} else {
|
||||
strippedChangeDir, _ := strings.CutPrefix(changeDir, "~/")
|
||||
changeDir = filepath.Join(homedir, strippedChangeDir)
|
||||
}
|
||||
}
|
||||
SELECTED_COMMAND = "cd \"" + changeDir + "\" && " + SELECTED_COMMAND
|
||||
}
|
||||
return ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user