Default config improvements (#4565)

* Default config improvements

* Finish cleanup

* Add some comments
This commit is contained in:
JT 2022-02-20 07:48:46 -05:00 committed by GitHub
parent 52ee1917ba
commit 643c5097d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 118 additions and 32 deletions

View file

@ -211,6 +211,26 @@ impl NuCompleter {
let mut output = vec![];
for named in &sig.named {
if let Some(short) = named.short {
let mut named = vec![0; short.len_utf8()];
short.encode_utf8(&mut named);
named.insert(0, b'-');
println!("{:?}", named);
if named.starts_with(&prefix) {
output.push((
reedline::Span {
start: new_span.start - offset,
end: new_span.end - offset,
},
String::from_utf8_lossy(&named).to_string(),
));
}
}
if named.long.is_empty() {
continue;
}
let mut named = named.long.as_bytes().to_vec();
named.insert(0, b'-');
named.insert(0, b'-');

View file

@ -84,7 +84,7 @@ pub(crate) fn read_config_file(
.expect("Failed to read user input");
match answer.to_lowercase().trim() {
"y" => {
"y" | "" => {
let mut output = File::create(&config_path).expect("Unable to create file");
let config_file = include_str!("default_config.nu");
write!(output, "{}", config_file).expect("Unable to write to config file");

View file

@ -1,17 +1,14 @@
# Nushell Config File
def create_left_prompt [] {
let path_segment = ([
($nu.cwd)
(char space)
] | str collect)
let path_segment = ($nu.cwd)
$path_segment
}
def create_right_prompt [] {
let time_segment = ([
(date now | date format '%m/%d/%Y %I:%M:%S%.3f')
(date now | date format '%m/%d/%Y %r')
] | str collect)
$time_segment
@ -28,33 +25,102 @@ let-env PROMPT_INDICATOR_VI_INSERT = ": "
let-env PROMPT_INDICATOR_VI_NORMAL = "〉"
let-env PROMPT_MULTILINE_INDICATOR = "::: "
# Custom completions for external commands (those outside of Nushell)
# Each completions has two parts: the form of the external command, including its flags and parameters
# and a helper command that knows how to complete values for those flags and parameters
#
# This is a simplified version of completions for git branches and git remotes
def "nu-complete git branches" [] {
^git branch | lines | each { |line| $line | str find-replace "\* " "" | str trim }
}
def "nu-complete git remotes" [] {
^git remote | lines | each { |line| $line | str trim }
}
extern "git checkout" [
branch?: string@"nu-complete git branches" # name of the branch to checkout
-b: string # create and checkout a new branch
-B: string # create/reset and checkout a branch
-l # create reflog for new branch
--guess # second guess 'git checkout <no-such-branch>' (default)
--overlay # use overlay mode (default)
--quiet(-q) # suppress progress reporting
--recurse-submodules: string # control recursive updating of submodules
--progress # force progress reporting
--merge(-m) # perform a 3-way merge with the new branch
--conflict: string # conflict style (merge or diff3)
--detach(-d) # detach HEAD at named commit
--track(-t) # set upstream info for new branch
--force(-f) # force checkout (throw away local modifications)
--orphan: string # new unparented branch
--overwrite-ignore # update ignored files (default)
--ignore-other-worktrees # do not check if another worktree is holding the given ref
--ours(-2) # checkout our version for unmerged files
--theirs(-3) # checkout their version for unmerged files
--patch(-p) # select hunks interactively
--ignore-skip-worktree-bits # do not limit pathspecs to sparse entries only
--pathspec-from-file: string # read pathspec from file
]
extern "git push" [
remote?: string@"nu-complete git remotes", # the name of the remote
refspec?: string@"nu-complete git branches"# the branch / refspec
--verbose(-v) # be more verbose
--quiet(-q) # be more quiet
--repo: string # repository
--all # push all refs
--mirror # mirror all refs
--delete(-d) # delete refs
--tags # push tags (can't be used with --all or --mirror)
--dry-run(-n) # dry run
--porcelain # machine-readable output
--force(-f) # force updates
--force-with-lease: string # require old value of ref to be at this value
--recurse-submodules: string # control recursive pushing of submodules
--thin # use thin pack
--receive-pack: string # receive pack program
--exec: string # receive pack program
--set-upstream(-u) # set upstream for git pull/status
--progress # force progress reporting
--prune # prune locally removed refs
--no-verify # bypass pre-push hook
--follow-tags # push missing but relevant tags
--signed: string # GPG sign the push
--atomic # request atomic transaction on remote side
--push-option(-o): string # option to transmit
--ipv4(-4) # use IPv4 addresses only
--ipv6(-6) # use IPv6 addresses only
]
# The default config record. This is where much of your global configuration is setup.
let $config = {
filesize_metric: $true
filesize_metric: $false
table_mode: rounded # basic, compact, compact_double, light, thin, with_love, rounded, reinforced, heavy, none, other
use_ls_colors: $true
rm_always_trash: $false
color_config: {
separator: yd
separator: white
leading_trailing_space_bg: white
header: cb
date: pu
filesize: ub
row_index: yb
header: green_bold
date: white
filesize: white
row_index: green_bold
hints: dark_gray
bool: red
int: green
duration: red
range: red
float: red
string: red
nothing: red
binary: red
cellpath: red
bool: white
int: white
duration: white
range: white
float: white
string: white
nothing: white
binary: white
cellpath: white
}
use_grid_icons: $true
footer_mode: always #always, never, number_of_rows, auto
quick_completions: $false
animate_prompt: $false
footer_mode: always # always, never, number_of_rows, auto
quick_completions: $false # set this to $true to auto-select completions when only one remains
animate_prompt: $false # redraw the prompt every second
float_precision: 2
use_ansi_coloring: $true
filesize_format: "b" # b, kb, kib, mb, mib, gb, gib, tb, tib, pb, pib, eb, eib, zb, zib, auto
@ -70,7 +136,7 @@ let $config = {
columns: 4
col_width: 20 # Optional value. If missing all the screen width is used to calculate column width
col_padding: 2
text_style: red
text_style: green
selected_text_style: green_reverse
marker: "| "
}
@ -82,12 +148,12 @@ let $config = {
marker: "? "
}
keybindings: [
{
name: completion
modifier: control
keycode: char_t
mode: vi_insert # emacs vi_normal vi_insert
event: { send: menu name: context_menu }
}
{
name: completion
modifier: control
keycode: char_t
mode: vi_insert # emacs vi_normal vi_insert
event: { send: menu name: context_menu }
}
]
}