mirror of
https://github.com/nushell/nushell.git
synced 2025-02-04 12:40:33 +01:00
84742275a1
# Description Add `ulimit` command to Nushell. Closes #9563 Closes #3976 Related pr #11246 Reference: https://github.com/fish-shell/fish-shell/blob/master/fish-rust/src/builtins/ulimit.rs https://github.com/mirror/busybox/blob/master/shell/shell_common.c#L529 # User-Facing Changes ``` nushell on ulimit is 📦 v0.88.2 via 🦀 v1.72.1 [3/246] ❯ ulimit -a ╭────┬──────────────────────────────────────────────────────────────────────────┬───────────┬───────────╮ │ # │ description │ soft │ hard │ ├────┼──────────────────────────────────────────────────────────────────────────┼───────────┼───────────┤ │ 0 │ Maximum size of core files created (kB, -c) │ unlimited │ unlimited │ │ 1 │ Maximum size of a process's data segment (kB, -d) │ unlimited │ unlimited │ │ 2 │ Controls of maximum nice priority (-e) │ 0 │ 0 │ │ 3 │ Maximum size of files created by the shell (kB, -f) │ unlimited │ unlimited │ │ 4 │ Maximum number of pending signals (-i) │ 55273 │ 55273 │ │ 5 │ Maximum size that may be locked into memory (kB, -l) │ 8192 │ 8192 │ │ 6 │ Maximum resident set size (kB, -m) │ unlimited │ unlimited │ │ 7 │ Maximum number of open file descriptors (-n) │ 1024 │ 524288 │ │ 8 │ Maximum bytes in POSIX message queues (kB, -q) │ 800 │ 800 │ │ 9 │ Maximum realtime scheduling priority (-r) │ 0 │ 0 │ │ 10 │ Maximum stack size (kB, -s) │ 8192 │ unlimited │ │ 11 │ Maximum amount of CPU time in seconds (seconds, -t) │ unlimited │ unlimited │ │ 12 │ Maximum number of processes available to the current user (-u) │ 55273 │ 55273 │ │ 13 │ Maximum amount of virtual memory available to each process (kB, -v) │ unlimited │ unlimited │ │ 14 │ Maximum number of file locks (-x) │ unlimited │ unlimited │ │ 15 │ Maximum contiguous realtime CPU time (-y) │ unlimited │ unlimited │ ╰────┴──────────────────────────────────────────────────────────────────────────┴───────────┴───────────╯ nushell on ulimit is 📦 v0.88.2 via 🦀 v1.72.1 ❯ ulimit -s ╭───┬─────────────────────────────┬──────┬───────────╮ │ # │ description │ soft │ hard │ ├───┼─────────────────────────────┼──────┼───────────┤ │ 0 │ Maximum stack size (kB, -s) │ 8192 │ unlimited │ ╰───┴─────────────────────────────┴──────┴───────────╯ nushell on ulimit is 📦 v0.88.2 via 🦀 v1.72.1 ❯ ulimit -s 100 nushell on ulimit is 📦 v0.88.2 via 🦀 v1.72.1 ❯ ulimit -s ╭───┬─────────────────────────────┬──────┬──────╮ │ # │ description │ soft │ hard │ ├───┼─────────────────────────────┼──────┼──────┤ │ 0 │ Maximum stack size (kB, -s) │ 100 │ 100 │ ╰───┴─────────────────────────────┴──────┴──────╯ nushell on ulimit is 📦 v0.88.2 via 🦀 v1.72.1 ``` # Tests + Formatting - [x] add commands::ulimit::limit_set_soft1 - [x] add commands::ulimit::limit_set_soft2 - [x] add commands::ulimit::limit_set_hard1 - [x] add commands::ulimit::limit_set_hard2 - [x] add commands::ulimit::limit_set_invalid1 - [x] add commands::ulimit::limit_set_invalid2 - [x] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - [x] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - [x] `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - [x] `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library
438 lines
8.9 KiB
Rust
438 lines
8.9 KiB
Rust
use nu_protocol::engine::{EngineState, StateWorkingSet};
|
|
|
|
use crate::{
|
|
help::{HelpAliases, HelpCommands, HelpEscapes, HelpExterns, HelpModules, HelpOperators},
|
|
*,
|
|
};
|
|
pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
|
|
let delta = {
|
|
let mut working_set = StateWorkingSet::new(&engine_state);
|
|
|
|
macro_rules! bind_command {
|
|
( $( $command:expr ),* $(,)? ) => {
|
|
$( working_set.add_decl(Box::new($command)); )*
|
|
};
|
|
}
|
|
|
|
// If there are commands that have the same name as default declarations,
|
|
// they have to be registered before the main declarations. This helps to make
|
|
// them only accessible if the correct input value category is used with the
|
|
// declaration
|
|
|
|
// Database-related
|
|
// Adds all related commands to query databases
|
|
#[cfg(feature = "sqlite")]
|
|
add_database_decls(&mut working_set);
|
|
|
|
// Charts
|
|
bind_command! {
|
|
Histogram
|
|
}
|
|
|
|
// Filters
|
|
bind_command! {
|
|
All,
|
|
Any,
|
|
Append,
|
|
Columns,
|
|
Compact,
|
|
Default,
|
|
Drop,
|
|
DropColumn,
|
|
DropNth,
|
|
Each,
|
|
Empty,
|
|
Enumerate,
|
|
Every,
|
|
Filter,
|
|
Find,
|
|
First,
|
|
Flatten,
|
|
Get,
|
|
Group,
|
|
GroupBy,
|
|
Headers,
|
|
Insert,
|
|
Items,
|
|
Join,
|
|
SplitBy,
|
|
Take,
|
|
Merge,
|
|
Move,
|
|
TakeWhile,
|
|
TakeUntil,
|
|
Last,
|
|
Length,
|
|
Lines,
|
|
ParEach,
|
|
Prepend,
|
|
Range,
|
|
Reduce,
|
|
Reject,
|
|
Rename,
|
|
Reverse,
|
|
Select,
|
|
Shuffle,
|
|
Skip,
|
|
SkipUntil,
|
|
SkipWhile,
|
|
Sort,
|
|
SortBy,
|
|
SplitList,
|
|
Transpose,
|
|
Uniq,
|
|
UniqBy,
|
|
Upsert,
|
|
Update,
|
|
Values,
|
|
Where,
|
|
Window,
|
|
Wrap,
|
|
Zip,
|
|
};
|
|
|
|
// Misc
|
|
bind_command! {
|
|
Source,
|
|
Tutor,
|
|
};
|
|
|
|
// Path
|
|
bind_command! {
|
|
Path,
|
|
PathBasename,
|
|
PathDirname,
|
|
PathExists,
|
|
PathExpand,
|
|
PathJoin,
|
|
PathParse,
|
|
PathRelativeTo,
|
|
PathSplit,
|
|
PathType,
|
|
};
|
|
|
|
// System
|
|
bind_command! {
|
|
Complete,
|
|
External,
|
|
Exec,
|
|
NuCheck,
|
|
Sys,
|
|
};
|
|
|
|
// Help
|
|
bind_command! {
|
|
Help,
|
|
HelpAliases,
|
|
HelpExterns,
|
|
HelpCommands,
|
|
HelpModules,
|
|
HelpOperators,
|
|
HelpEscapes,
|
|
};
|
|
|
|
// Debug
|
|
bind_command! {
|
|
Ast,
|
|
Debug,
|
|
DebugInfo,
|
|
Explain,
|
|
Inspect,
|
|
Metadata,
|
|
TimeIt,
|
|
View,
|
|
ViewFiles,
|
|
ViewSource,
|
|
ViewSpan,
|
|
};
|
|
|
|
#[cfg(windows)]
|
|
bind_command! { RegistryQuery }
|
|
|
|
#[cfg(any(
|
|
target_os = "android",
|
|
target_os = "linux",
|
|
target_os = "macos",
|
|
target_os = "windows"
|
|
))]
|
|
bind_command! { Ps };
|
|
|
|
#[cfg(feature = "which-support")]
|
|
bind_command! { Which };
|
|
|
|
// Strings
|
|
bind_command! {
|
|
Char,
|
|
Decode,
|
|
Encode,
|
|
DecodeBase64,
|
|
EncodeBase64,
|
|
DetectColumns,
|
|
Parse,
|
|
Split,
|
|
SplitChars,
|
|
SplitColumn,
|
|
SplitRow,
|
|
SplitWords,
|
|
Str,
|
|
StrCapitalize,
|
|
StrContains,
|
|
StrDistance,
|
|
StrDowncase,
|
|
StrEndswith,
|
|
StrExpand,
|
|
StrJoin,
|
|
StrReplace,
|
|
StrIndexOf,
|
|
StrLength,
|
|
StrReverse,
|
|
StrStats,
|
|
StrStartsWith,
|
|
StrSubstring,
|
|
StrTrim,
|
|
StrUpcase,
|
|
Format,
|
|
FormatDate,
|
|
FormatDuration,
|
|
FormatFilesize,
|
|
};
|
|
|
|
// FileSystem
|
|
bind_command! {
|
|
Cd,
|
|
Ls,
|
|
Mkdir,
|
|
UMkdir,
|
|
Mktemp,
|
|
Mv,
|
|
Cp,
|
|
UCp,
|
|
Open,
|
|
Start,
|
|
Rm,
|
|
Save,
|
|
Touch,
|
|
Glob,
|
|
Watch,
|
|
};
|
|
|
|
// Platform
|
|
bind_command! {
|
|
Ansi,
|
|
AnsiLink,
|
|
AnsiStrip,
|
|
Clear,
|
|
Du,
|
|
Input,
|
|
InputList,
|
|
InputListen,
|
|
IsTerminal,
|
|
Kill,
|
|
Sleep,
|
|
TermSize,
|
|
Whoami,
|
|
};
|
|
|
|
#[cfg(unix)]
|
|
bind_command! { ULimit };
|
|
|
|
// Date
|
|
bind_command! {
|
|
Date,
|
|
DateHumanize,
|
|
DateListTimezones,
|
|
DateNow,
|
|
DateToRecord,
|
|
DateToTable,
|
|
DateToTimezone,
|
|
};
|
|
|
|
// Shells
|
|
bind_command! {
|
|
Exit,
|
|
};
|
|
|
|
// Formats
|
|
bind_command! {
|
|
From,
|
|
FromCsv,
|
|
FromJson,
|
|
FromNuon,
|
|
FromOds,
|
|
FromSsv,
|
|
FromToml,
|
|
FromTsv,
|
|
FromXlsx,
|
|
FromXml,
|
|
FromYaml,
|
|
FromYml,
|
|
To,
|
|
ToCsv,
|
|
ToJson,
|
|
ToMd,
|
|
ToNuon,
|
|
ToText,
|
|
ToToml,
|
|
ToTsv,
|
|
Touch,
|
|
Upsert,
|
|
Where,
|
|
ToXml,
|
|
ToYaml,
|
|
};
|
|
|
|
// Viewers
|
|
bind_command! {
|
|
Griddle,
|
|
Table,
|
|
};
|
|
|
|
// Conversions
|
|
bind_command! {
|
|
Fill,
|
|
Into,
|
|
IntoBool,
|
|
IntoBinary,
|
|
IntoDatetime,
|
|
IntoDuration,
|
|
IntoFloat,
|
|
IntoFilesize,
|
|
IntoInt,
|
|
IntoRecord,
|
|
IntoString,
|
|
IntoValue,
|
|
};
|
|
|
|
// Env
|
|
bind_command! {
|
|
ExportEnv,
|
|
LoadEnv,
|
|
SourceEnv,
|
|
WithEnv,
|
|
ConfigNu,
|
|
ConfigEnv,
|
|
ConfigMeta,
|
|
ConfigReset,
|
|
};
|
|
|
|
// Math
|
|
bind_command! {
|
|
Math,
|
|
MathAbs,
|
|
MathAvg,
|
|
MathCeil,
|
|
MathFloor,
|
|
MathMax,
|
|
MathMedian,
|
|
MathMin,
|
|
MathMode,
|
|
MathProduct,
|
|
MathRound,
|
|
MathSqrt,
|
|
MathStddev,
|
|
MathSum,
|
|
MathVariance,
|
|
MathLog,
|
|
};
|
|
|
|
// Bytes
|
|
bind_command! {
|
|
Bytes,
|
|
BytesLen,
|
|
BytesStartsWith,
|
|
BytesEndsWith,
|
|
BytesReverse,
|
|
BytesReplace,
|
|
BytesAdd,
|
|
BytesAt,
|
|
BytesIndexOf,
|
|
BytesCollect,
|
|
BytesRemove,
|
|
BytesBuild
|
|
}
|
|
|
|
// Network
|
|
bind_command! {
|
|
Http,
|
|
HttpDelete,
|
|
HttpGet,
|
|
HttpHead,
|
|
HttpPatch,
|
|
HttpPost,
|
|
HttpPut,
|
|
HttpOptions,
|
|
Url,
|
|
UrlBuildQuery,
|
|
UrlDecode,
|
|
UrlEncode,
|
|
UrlJoin,
|
|
UrlParse,
|
|
Port,
|
|
}
|
|
|
|
// Random
|
|
bind_command! {
|
|
Random,
|
|
RandomBool,
|
|
RandomChars,
|
|
RandomDice,
|
|
RandomFloat,
|
|
RandomInt,
|
|
RandomUuid,
|
|
};
|
|
|
|
// Generators
|
|
bind_command! {
|
|
Cal,
|
|
Seq,
|
|
SeqDate,
|
|
SeqChar,
|
|
Generate,
|
|
};
|
|
|
|
// Hash
|
|
bind_command! {
|
|
Hash,
|
|
HashMd5::default(),
|
|
HashSha256::default(),
|
|
};
|
|
|
|
// Experimental
|
|
bind_command! {
|
|
IsAdmin,
|
|
};
|
|
|
|
// Removed
|
|
bind_command! {
|
|
LetEnv,
|
|
DateFormat,
|
|
};
|
|
|
|
// Stor
|
|
#[cfg(feature = "sqlite")]
|
|
bind_command! {
|
|
Stor,
|
|
StorCreate,
|
|
StorDelete,
|
|
StorExport,
|
|
StorImport,
|
|
StorInsert,
|
|
StorOpen,
|
|
StorReset,
|
|
StorUpdate,
|
|
};
|
|
|
|
working_set.render()
|
|
};
|
|
|
|
if let Err(err) = engine_state.merge_delta(delta) {
|
|
eprintln!("Error creating default context: {err:?}");
|
|
}
|
|
|
|
// Cache the table decl id so we don't have to look it up later
|
|
let table_decl_id = engine_state.find_decl("table".as_bytes(), &[]);
|
|
engine_state.table_decl_id = table_decl_id;
|
|
|
|
engine_state
|
|
}
|