mirror of
https://codeberg.org/TicklishHoneyBee/CLIte.git
synced 2026-03-11 09:04:37 +00:00
add the start of shell history saving
This commit is contained in:
parent
98bedb8ca0
commit
7ceb503fee
1 changed files with 34 additions and 2 deletions
|
|
@ -89,11 +89,10 @@ clite.commands.load('sh',function(args,env,io) {
|
|||
return 1;
|
||||
},
|
||||
exit:function(args,io) {
|
||||
has_exited = true;
|
||||
var ev = 0;
|
||||
if (args.length > 1)
|
||||
ev = parseInt(args[1]);
|
||||
io.exit(ev);
|
||||
doShellExit(ev);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
|
@ -102,6 +101,27 @@ clite.commands.load('sh',function(args,env,io) {
|
|||
data:[],
|
||||
current:'',
|
||||
index:0,
|
||||
load:function() {
|
||||
let path = clite.resolvePath('~/.shhistory');
|
||||
let fd = stdio.open(path,stdio.flags.O_RDONLY|stdio.flags.O_SYNC);
|
||||
if (!fd)
|
||||
return;
|
||||
var e;
|
||||
while ((e = stdio.readLine(fd)) != null) {
|
||||
history.add(e);
|
||||
}
|
||||
stdio.close(fd);
|
||||
},
|
||||
save:function() {
|
||||
let path = clite.resolvePath('~/.shhistory');
|
||||
let fd = stdio.open(path,stdio.flags.O_WRONLY|stdio.flags.O_TRUNC|stdio.flags.O_CREAT|stdio.flags.O_SYNC);
|
||||
if (!fd)
|
||||
return;
|
||||
history.data.forEach(function(l) {
|
||||
stdio.write(fd,l+'\n');
|
||||
});
|
||||
stdio.close(fd);
|
||||
},
|
||||
add:function(txt) {
|
||||
if (txt.length < 1)
|
||||
return;
|
||||
|
|
@ -816,6 +836,13 @@ Options:
|
|||
`);
|
||||
}
|
||||
|
||||
function doShellExit(v) {
|
||||
history.save();
|
||||
stdio.write(io.stdout,'\n');
|
||||
has_exited = true;
|
||||
io.exit(v);
|
||||
}
|
||||
|
||||
function resolvePATH(txt) {
|
||||
// special case of test command
|
||||
if (txt == '[')
|
||||
|
|
@ -953,6 +980,10 @@ Options:
|
|||
|
||||
function inputProcess(str) {
|
||||
switch (str) {
|
||||
case String.fromCharCode(4):
|
||||
case 4:
|
||||
doShellExit(0);
|
||||
break;
|
||||
case '\t': // tab
|
||||
case 9:
|
||||
var ct = tabfill(c);
|
||||
|
|
@ -1075,6 +1106,7 @@ Options:
|
|||
parser.queue(env.HOME+'/.shrc');
|
||||
parser.run(function() {
|
||||
history.clear();
|
||||
history.load();
|
||||
inputRead();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue