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
Feature request: export history to local history file #1073
Comments
Wrote a simple script to export history into fish local file. package main
import (
"database/sql"
"fmt"
"os"
_ "github.com/mattn/go-sqlite3"
)
var (
home string
)
func init() {
home, _ = os.UserHomeDir()
}
func writeFishHistoryFile(t int, cmd string) {
file, err := os.OpenFile(home+"/.local/share/fish/fish_history", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
panic(err)
}
defer file.Close()
content := fmt.Sprintf("- cmd: %s\n when: %d\n", cmd, t/1000000000)
_, err = file.WriteString(content)
if err != nil {
panic(err)
}
}
func main() {
db, err := sql.Open("sqlite3", home+"/.local/share/atuin/history.db")
if err != nil {
fmt.Println(err)
return
}
defer db.Close()
rows, err := db.Query("SELECT * FROM history ORDER BY timestamp ASC")
if err != nil {
fmt.Println(err)
return
}
defer rows.Close()
for rows.Next() {
var id, command, cwd, session, hostname string
var timestamp, duration, exit int
var deleted_at interface{}
err = rows.Scan(&id, ×tamp, &duration, &exit, &command, &cwd, &session, &hostname, &deleted_at)
if err != nil {
fmt.Println(err)
continue
}
writeFishHistoryFile(timestamp, command)
}
err = rows.Err()
if err != nil {
fmt.Println(err)
return
}
} |
Thank you for the script! Otherwise, this is a a dupe of #816 |
|
for zsh_history import subprocess
from datetime import datetime
dst = 'zsh_history.out'
cmd = 'atuin history list --format {time}:0;{command}'
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
with open(dst, 'w', encoding='utf8') as f_dst:
line_continue = False
while True:
line = p.stdout.readline()
if line == b'':
break
line = line.decode(encoding='utf-8')
if line_continue:
f_dst.write(line)
else:
try:
dt = datetime.strptime(line[0:19], '%Y-%m-%d %H:%M:%S')
f_dst.write(f': {int(dt.timestamp())}')
f_dst.write(line[19:])
except ValueError as e:
print(f'error={e}, line={line}')
line_continue = line.rstrip().endswith('\\') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After I set up
atuin sync
on the new device, I found that fish Auto Suggestions are not working.Guess it's because there is no command history in the fish's history file.
So, can we add an command to export
atuin history
to the local history file?The text was updated successfully, but these errors were encountered: