aboutsummaryrefslogtreecommitdiffstats
path: root/ui/src/state/models.ts
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2024-05-14 12:16:04 +0700
committerGitHub <noreply@github.com>2024-05-14 12:16:04 +0700
commit34265613b80d1d2249d276da5fcd5e4c274af357 (patch)
tree0993650d0a8475f37dfdb8ead5491ee5d196f00e /ui/src/state/models.ts
parentfix: alias enable/enabled in settings (#2021) (diff)
downloadatuin-34265613b80d1d2249d276da5fcd5e4c274af357.zip
feat(ui): add history explore (#2022)
* break out HistoryRow, add drawer * syntax highlighting! * smaller text * allow inspecting all old commands, no drag command * fix query bug * add loader
Diffstat (limited to 'ui/src/state/models.ts')
-rw-r--r--ui/src/state/models.ts68
1 files changed, 63 insertions, 5 deletions
diff --git a/ui/src/state/models.ts b/ui/src/state/models.ts
index 5aca83a0..b92d64a6 100644
--- a/ui/src/state/models.ts
+++ b/ui/src/state/models.ts
@@ -28,23 +28,29 @@ export class ShellHistory {
host: string;
cwd: string;
duration: number;
+ exit: number;
+ /// Pass a row straight from the database to this
constructor(
id: string,
timestamp: number,
command: string,
- user: string,
- host: string,
+ hostuser: string,
cwd: string,
duration: number,
+ exit: number,
) {
this.id = id;
this.timestamp = timestamp;
this.command = command;
+
+ let [host, user] = hostuser.split(":");
this.user = user;
this.host = host;
+
this.cwd = cwd;
this.duration = duration;
+ this.exit = exit;
}
}
@@ -59,12 +65,64 @@ export interface Var {
export: boolean;
}
-export async function inspectHistory(id: string): Promise<any> {
+export interface InspectHistory {
+ other: ShellHistory[];
+}
+
+export async function inspectCommandHistory(
+ h: ShellHistory,
+): Promise<InspectHistory> {
const db = await Database.load(
"sqlite:/Users/ellie/.local/share/atuin/history.db",
);
- let res = await db.select("select * from history where id=$1", [id]);
+ let other: any[] = await db.select(
+ "select * from history where command=?1 order by timestamp desc",
+ [h.command],
+ );
+ console.log(other);
+
+ return {
+ other: other.map(
+ (i) =>
+ new ShellHistory(
+ i.id,
+ i.timestamp,
+ i.command,
+ i.hostname,
+ i.cwd,
+ i.duration,
+ i.exit,
+ ),
+ ),
+ };
+}
+
+export async function inspectDirectoryHistory(
+ h: ShellHistory,
+): Promise<InspectHistory> {
+ const db = await Database.load(
+ "sqlite:/Users/ellie/.local/share/atuin/history.db",
+ );
+
+ let other: any[] = await db.select(
+ "select * from history where cwd=?1 order by timestamp desc",
+ [h.cwd],
+ );
+ console.log(other);
- return res;
+ return {
+ other: other.map(
+ (i) =>
+ new ShellHistory(
+ i.id,
+ i.timestamp,
+ i.command,
+ i.hostname,
+ i.cwd,
+ i.duration,
+ i.exit,
+ ),
+ ),
+ };
}