aboutsummaryrefslogtreecommitdiffstats
path: root/ui/src/state
diff options
context:
space:
mode:
Diffstat (limited to 'ui/src/state')
-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,
+ ),
+ ),
+ };
}