Skip to content

Commit 43a2a58

Browse files
committed
feat(cli/nushell): modularize, add jc
1 parent ccd099f commit 43a2a58

File tree

6 files changed

+104
-95
lines changed

6 files changed

+104
-95
lines changed

home/gabriel/features/cli/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{pkgs, ...}: {
22
imports = [
33
./fish
4+
./nushell
45

56
./bash.nix
67
./bat.nix
@@ -10,7 +11,6 @@
1011
./gpg.nix
1112
./jujutsu.nix
1213
./lyrics.nix
13-
./nushell.nix
1414
./nix-index.nix
1515
./pfetch.nix
1616
./ssh.nix

home/gabriel/features/cli/nushell.nix

Lines changed: 0 additions & 94 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
let fish_completer = {|spans|
2+
fish --command $"complete '--do-complete=($spans | str replace --all "'" "\\'" | str join ' ')'"
3+
| from tsv --flexible --noheaders --no-infer
4+
| rename value description
5+
| update value {|row|
6+
let value = $row.value
7+
let need_quote = ['\' ',' '[' ']' '(' ')' ' ' '\t' "'" '"' "`"] | any {$in in $value}
8+
if ($need_quote and ($value | path exists)) {
9+
let expanded_path = if ($value starts-with ~) {$value | path expand --no-symlink} else {$value}
10+
$'"($expanded_path | str replace --all "\"" "\\\"")"'
11+
} else {$value}
12+
}
13+
}
14+
15+
$env.config.completions.external.enable = true
16+
$env.config.completions.external.completer = $fish_completer
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
imports = [
3+
./jc.nix
4+
];
5+
programs.nushell = {
6+
enable = true;
7+
extraConfig = /* nu */ ''
8+
def create_title [] {
9+
let prefix = if SSH_TTY in $env {$"[(hostname | str replace -r "\\..*" "")] "}
10+
let path = pwd | str replace $env.HOME "~"
11+
([$prefix, $path] | str join)
12+
}
13+
14+
$env.config = {
15+
edit_mode: vi,
16+
show_banner: false,
17+
use_kitty_protocol: true,
18+
shell_integration: {
19+
osc2: false,
20+
osc7: true,
21+
osc8: true,
22+
osc133: true,
23+
osc633: true,
24+
reset_application_mode: true,
25+
},
26+
completions: {
27+
algorithm: "fuzzy",
28+
},
29+
history: {
30+
sync_on_enter: true,
31+
},
32+
hooks: {
33+
pre_prompt: [{
34+
print -n $"(ansi title)(create_title)(ansi st)"
35+
}]
36+
}
37+
}
38+
39+
source ${./prompt.nu}
40+
source ${./completion.nu}
41+
'';
42+
};
43+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{pkgs, ...}: {
2+
home.packages = [pkgs.jc];
3+
programs.nushell.extraConfig = /*nu*/ ''
4+
use ${pkgs.nu_scripts}/share/nu_scripts/modules/jc
5+
'';
6+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
def create_left_prompt [] {
2+
let dir = match (do --ignore-errors { $env.PWD | path relative-to $nu.home-path }) {
3+
null => $env.PWD
4+
'' => '~'
5+
$relative_pwd => ([~ $relative_pwd] | path join)
6+
}
7+
8+
let path_color = (if (is-admin) { ansi red_bold } else { ansi green_bold })
9+
let separator_color = (if (is-admin) { ansi light_red_bold } else { ansi light_green_bold })
10+
let path_segment = $"($path_color)($dir)"
11+
12+
$path_segment | str replace --all (char path_sep) $"($separator_color)(char path_sep)($path_color)"
13+
}
14+
15+
def create_right_prompt [] {
16+
# create a right prompt in magenta with green separators and am/pm underlined
17+
let time_segment = ([
18+
(ansi reset)
19+
(ansi magenta)
20+
(date now | format date '%x %X') # try to respect user's locale
21+
] | str join | str replace --regex --all "([/:])" $"(ansi green)${1}(ansi magenta)" |
22+
str replace --regex --all "([AP]M)" $"(ansi magenta_underline)${1}")
23+
24+
let last_exit_code = if ($env.LAST_EXIT_CODE != 0) {([
25+
(ansi rb)
26+
($env.LAST_EXIT_CODE)
27+
] | str join)
28+
} else { "" }
29+
30+
([$last_exit_code, (char space), $time_segment] | str join)
31+
}
32+
33+
$env.PROMPT_COMMAND = { || create_left_prompt }
34+
$env.PROMPT_COMMAND_RIGHT = { || create_right_prompt }
35+
$env.PROMPT_INDICATOR = {|| "> " }
36+
$env.PROMPT_INDICATOR_VI_INSERT = {|| "> " }
37+
$env.PROMPT_INDICATOR_VI_NORMAL = {|| "| " }
38+
$env.PROMPT_MULTILINE_INDICATOR = {|| "::: " }

0 commit comments

Comments
 (0)