2021-09-03 00:58:15 +02:00
|
|
|
use nu_protocol::{
|
|
|
|
engine::{EngineState, StateWorkingSet},
|
2021-10-01 23:53:13 +02:00
|
|
|
Signature,
|
2021-09-03 00:58:15 +02:00
|
|
|
};
|
|
|
|
|
2021-10-02 04:59:11 +02:00
|
|
|
use crate::*;
|
2021-09-03 00:58:15 +02:00
|
|
|
|
2021-10-25 08:31:39 +02:00
|
|
|
pub fn create_default_context() -> EngineState {
|
|
|
|
let mut engine_state = EngineState::new();
|
2021-10-28 06:13:10 +02:00
|
|
|
|
2021-09-03 00:58:15 +02:00
|
|
|
let delta = {
|
2021-10-25 08:31:39 +02:00
|
|
|
let mut working_set = StateWorkingSet::new(&engine_state);
|
2021-09-03 00:58:15 +02:00
|
|
|
|
2021-10-10 06:13:15 +02:00
|
|
|
macro_rules! bind_command {
|
|
|
|
( $command:expr ) => {
|
|
|
|
working_set.add_decl(Box::new($command));
|
|
|
|
};
|
|
|
|
( $( $command:expr ),* ) => {
|
|
|
|
$( working_set.add_decl(Box::new($command)); )*
|
|
|
|
};
|
|
|
|
}
|
2021-09-23 21:03:08 +02:00
|
|
|
|
2021-10-12 19:44:23 +02:00
|
|
|
// TODO: sort default context items categorically
|
2021-10-10 22:24:54 +02:00
|
|
|
bind_command!(
|
|
|
|
Alias,
|
|
|
|
Benchmark,
|
|
|
|
BuildString,
|
|
|
|
Cd,
|
|
|
|
Cp,
|
2021-10-31 07:54:51 +01:00
|
|
|
Date,
|
|
|
|
DateFormat,
|
|
|
|
DateHumanize,
|
|
|
|
DateListTimezones,
|
|
|
|
DateNow,
|
|
|
|
DateToTable,
|
|
|
|
DateToTimezone,
|
2021-10-10 22:24:54 +02:00
|
|
|
Def,
|
|
|
|
Do,
|
|
|
|
Each,
|
2021-11-01 09:12:48 +01:00
|
|
|
Echo,
|
2021-10-10 22:24:54 +02:00
|
|
|
ExportDef,
|
|
|
|
External,
|
2021-10-31 22:53:37 +01:00
|
|
|
First,
|
2021-10-10 22:24:54 +02:00
|
|
|
For,
|
|
|
|
From,
|
|
|
|
FromJson,
|
|
|
|
Get,
|
|
|
|
Griddle,
|
|
|
|
Help,
|
|
|
|
Hide,
|
|
|
|
If,
|
2021-10-11 03:57:39 +02:00
|
|
|
Into,
|
|
|
|
IntoBinary,
|
|
|
|
IntoFilesize,
|
|
|
|
IntoInt,
|
2021-10-26 20:29:00 +02:00
|
|
|
Last,
|
2021-10-10 22:24:54 +02:00
|
|
|
Length,
|
|
|
|
Let,
|
|
|
|
LetEnv,
|
|
|
|
Lines,
|
|
|
|
Ls,
|
2021-10-25 01:58:18 +02:00
|
|
|
Math,
|
|
|
|
MathAbs,
|
2021-10-27 03:00:50 +02:00
|
|
|
MathAvg,
|
2021-11-03 01:17:27 +01:00
|
|
|
MathFloor,
|
2021-10-29 21:02:42 +02:00
|
|
|
MathMax,
|
|
|
|
MathMin,
|
2021-11-01 22:29:34 +01:00
|
|
|
MathProduct,
|
|
|
|
MathRound,
|
|
|
|
MathSqrt,
|
|
|
|
MathSum,
|
2021-11-03 01:17:27 +01:00
|
|
|
MathMode,
|
2021-10-10 22:24:54 +02:00
|
|
|
Mkdir,
|
|
|
|
Module,
|
|
|
|
Mv,
|
2021-10-26 03:30:53 +02:00
|
|
|
ParEach,
|
2021-10-10 22:24:54 +02:00
|
|
|
Ps,
|
2021-10-31 09:17:01 +01:00
|
|
|
Register,
|
2021-10-30 19:51:20 +02:00
|
|
|
Range,
|
2021-10-10 22:24:54 +02:00
|
|
|
Rm,
|
2021-10-23 22:08:54 +02:00
|
|
|
RunPlugin,
|
2021-10-10 22:24:54 +02:00
|
|
|
Select,
|
2021-10-12 23:55:29 +02:00
|
|
|
Size,
|
2021-10-10 22:24:54 +02:00
|
|
|
Split,
|
|
|
|
SplitChars,
|
|
|
|
SplitColumn,
|
|
|
|
SplitRow,
|
|
|
|
Sys,
|
|
|
|
Table,
|
2021-10-29 08:26:29 +02:00
|
|
|
To,
|
|
|
|
ToJson,
|
2021-10-10 22:24:54 +02:00
|
|
|
Touch,
|
|
|
|
Use,
|
|
|
|
Where,
|
2021-11-02 06:28:28 +01:00
|
|
|
Wrap,
|
|
|
|
Zip
|
2021-10-10 22:24:54 +02:00
|
|
|
);
|
2021-09-03 04:15:01 +02:00
|
|
|
|
2021-09-14 06:59:46 +02:00
|
|
|
// This is a WIP proof of concept
|
2021-10-10 06:13:15 +02:00
|
|
|
bind_command!(ListGitBranches, Git, GitCheckout, Source);
|
2021-09-11 06:54:24 +02:00
|
|
|
|
2021-09-03 00:58:15 +02:00
|
|
|
let sig = Signature::build("exit");
|
|
|
|
working_set.add_decl(sig.predeclare());
|
|
|
|
|
|
|
|
working_set.render()
|
|
|
|
};
|
|
|
|
|
2021-11-02 20:53:48 +01:00
|
|
|
engine_state.merge_delta(delta);
|
2021-09-03 00:58:15 +02:00
|
|
|
|
|
|
|
engine_state
|
|
|
|
}
|