299 lines
9.8 KiB
Nix
299 lines
9.8 KiB
Nix
{
|
|
lib,
|
|
pkgs,
|
|
# inputs,
|
|
# getFlakePkg',
|
|
config,
|
|
...
|
|
}:
|
|
let
|
|
inherit (pkgs) nushell;
|
|
# init =
|
|
# let
|
|
# comma = lib.getExe' (getFlakePkg' inputs.nix-index-database "comma-with-db") "comma";
|
|
# in
|
|
# ''
|
|
# function fish_greeting
|
|
# ${./rice/header.sh}
|
|
# echo ""
|
|
# end
|
|
# function fish_title
|
|
# set -q argv[1]; or set argv fish
|
|
# echo (fish_prompt_pwd_dir_length=100 prompt_pwd): $argv;
|
|
# end
|
|
# function fish_command_not_found
|
|
# ${comma} $argv
|
|
# end
|
|
# '';
|
|
prompt = ''
|
|
do --env {
|
|
def prompt-header [
|
|
--left-char: string
|
|
]: nothing -> string {
|
|
let code = $env.LAST_EXIT_CODE
|
|
|
|
let jj_workspace_root = try {
|
|
jj workspace root err>| ignore
|
|
} catch {
|
|
""
|
|
}
|
|
|
|
let hostname = if ($env.SSH_CONNECTION? | is-not-empty) {
|
|
let hostname = try {
|
|
hostname
|
|
} catch {
|
|
"remote"
|
|
}
|
|
|
|
$"(ansi light_green_bold)@($hostname)(ansi reset) "
|
|
} else {
|
|
""
|
|
}
|
|
|
|
# https://github.com/nushell/nushell/issues/16205
|
|
#
|
|
# Case insensitive filesystems strike again!
|
|
let pwd = pwd | path expand
|
|
|
|
let body = if ($jj_workspace_root | is-not-empty) {
|
|
let subpath = $pwd | path relative-to $jj_workspace_root
|
|
let subpath = if ($subpath | is-not-empty) {
|
|
$"(ansi magenta_bold) → (ansi reset)(ansi blue)($subpath)"
|
|
}
|
|
|
|
$"($hostname)(ansi light_yellow_bold)($jj_workspace_root | path basename)($subpath)(ansi reset)"
|
|
} else {
|
|
let pwd = if ($pwd | str starts-with $env.HOME) {
|
|
"~" | path join ($pwd | path relative-to $env.HOME)
|
|
} else {
|
|
$pwd
|
|
}
|
|
|
|
$"($hostname)(ansi cyan)($pwd)(ansi reset)"
|
|
}
|
|
|
|
let command_duration = ($env.CMD_DURATION_MS | into int) * 1ms
|
|
let command_duration = if $command_duration <= 2sec {
|
|
""
|
|
} else {
|
|
$"┫(ansi light_magenta_bold)($command_duration)(ansi light_yellow_bold)┣━"
|
|
}
|
|
|
|
let exit_code = if $code == 0 {
|
|
""
|
|
} else {
|
|
$"┫(ansi light_red_bold)($code)(ansi light_yellow_bold)┣━"
|
|
}
|
|
|
|
let middle = if $command_duration == "" and $exit_code == "" {
|
|
"━"
|
|
} else {
|
|
""
|
|
}
|
|
|
|
$"(ansi light_yellow_bold)($left_char)($exit_code)($middle)($command_duration)(ansi reset) ($body)(char newline)"
|
|
}
|
|
|
|
$env.PROMPT_INDICATOR = $"(ansi light_yellow_bold)┃(ansi reset) "
|
|
$env.PROMPT_INDICATOR_VI_NORMAL = $env.PROMPT_INDICATOR
|
|
$env.PROMPT_INDICATOR_VI_INSERT = $env.PROMPT_INDICATOR
|
|
$env.PROMPT_MULTILINE_INDICATOR = $env.PROMPT_INDICATOR
|
|
$env.PROMPT_COMMAND = {||
|
|
prompt-header --left-char "┏"
|
|
}
|
|
$env.PROMPT_COMMAND_RIGHT = {||
|
|
let jj_status = try {
|
|
jj --quiet --color always --ignore-working-copy log --no-graph --revisions @ --template '
|
|
separate(
|
|
" ",
|
|
if(empty, label("empty", "(empty)")),
|
|
coalesce(
|
|
surround(
|
|
"\"",
|
|
"\"",
|
|
if(
|
|
description.first_line().substr(0, 24).starts_with(description.first_line()),
|
|
description.first_line().substr(0, 24),
|
|
description.first_line().substr(0, 23) ++ "…"
|
|
)
|
|
),
|
|
label(if(empty, "empty"), description_placeholder)
|
|
),
|
|
bookmarks.join(", "),
|
|
change_id.shortest(),
|
|
commit_id.shortest(),
|
|
if(conflict, label("conflict", "(conflict)")),
|
|
if(divergent, label("divergent prefix", "(divergent)")),
|
|
if(hidden, label("hidden prefix", "(hidden)")),
|
|
)
|
|
' err>| ignore
|
|
} catch {
|
|
""
|
|
}
|
|
|
|
$jj_status
|
|
}
|
|
}
|
|
'';
|
|
aliases = {
|
|
"l" = "ls";
|
|
"la" = "ls -a";
|
|
"gco" = "git checkout";
|
|
"gcb" = "git checkout -b";
|
|
"gp" = "git push";
|
|
"gpf" = "git push --force";
|
|
"gl" = "git pull";
|
|
"ga" = "git add";
|
|
"gcam" = "git commit -am";
|
|
"gcl" = "git clone";
|
|
"gcd" = "git clone --depth 1";
|
|
"lg" = "lazygit";
|
|
":q" = "exit";
|
|
"fg" = "job unfreeze";
|
|
"jobs" = "job list";
|
|
};
|
|
nuScriptsPath = "${pkgs.nu_scripts}/share/nu_scripts";
|
|
nuConfig = pkgs.writeText "config.nu" ''
|
|
use std/config *
|
|
|
|
${lib.mapAttrsToList (n: v: "alias ${n} = ${v}") aliases |> lib.concatStringsSep "\n"}
|
|
$env.NU_LIB_DIRS = ( $env.NU_LIB_DIRS | append "${nuScriptsPath}")
|
|
|
|
use ${nuScriptsPath}/modules/capture-foreign-env
|
|
source ${nuScriptsPath}/modules/formats/from-env.nu
|
|
|
|
let nixos_env = ('source /etc/set-environment' | capture-foreign-env --shell bash)
|
|
if ($nixos_env | describe | str starts-with "record") { $nixos_env | load-env }
|
|
|
|
source ${(pkgs.runCommand "zoxide.nu" { } ''${pkgs.zoxide}/bin/zoxide init nushell >> "$out"'')}
|
|
|
|
|
|
$env.config.buffer_editor = "${lib.getExe config.apps.editor}"
|
|
|
|
def fresh [] {
|
|
clear
|
|
${./rice/header.sh}
|
|
echo
|
|
}
|
|
|
|
def gap [] {
|
|
git commit -a --amend --no-edit
|
|
git push --force
|
|
}
|
|
|
|
# direnv
|
|
|
|
# Initialize the PWD hook as an empty list if it doesn't exist
|
|
$env.config.hooks.env_change.PWD = $env.config.hooks.env_change.PWD? | default []
|
|
|
|
$env.config.hooks.env_change.PWD ++= [{||
|
|
if (which direnv | is-empty) {
|
|
# If direnv isn't installed, do nothing
|
|
return
|
|
}
|
|
|
|
direnv export json | from json | default {} | load-env
|
|
# If direnv changes the PATH, it will become a string and we need to re-convert it to a list
|
|
$env.PATH = do (env-conversions).path.from_string $env.PATH
|
|
}]
|
|
|
|
# $cmd doesn't carry its args ?
|
|
# $env.config.hooks.command_not_found = { |cmd| , $cmd; echo }
|
|
|
|
$env.config.table.mode = "none";
|
|
$env.config.edit_mode = "vi";
|
|
$env.config.completions.algorithm = "fuzzy";
|
|
|
|
# TODO
|
|
$env.config.color_config = {
|
|
# separator default
|
|
# header green_bold
|
|
# empty blue
|
|
# bool light_cyan
|
|
# int default
|
|
# filesize cyan
|
|
# duration default
|
|
# datetime purple
|
|
# range default
|
|
# float default
|
|
# string default
|
|
# nothing default
|
|
# binary default
|
|
# cell-path default
|
|
# row_index green_bold
|
|
# record default
|
|
# list default
|
|
# block default
|
|
# hints dark_gray
|
|
# search_result bg red
|
|
# fg white
|
|
# shape_binary purple_bold
|
|
# shape_block blue_bold
|
|
# shape_bool light_cyan
|
|
# shape_closure green_bold
|
|
# shape_custom green
|
|
# shape_datetime cyan_bold
|
|
# shape_directory cyan
|
|
# shape_external cyan
|
|
# shape_externalarg green_bold
|
|
# shape_external_resolved light_yellow_bold
|
|
# shape_filepath cyan
|
|
# shape_flag blue_bold
|
|
# shape_float purple_bold
|
|
# shape_garbage fg white
|
|
# bg red
|
|
# attr b
|
|
# shape_glob_interpolation cyan_bold
|
|
# shape_globpattern cyan_bold
|
|
# shape_int purple_bold
|
|
# shape_internalcall cyan_bold
|
|
# shape_keyword cyan_bold
|
|
# shape_list cyan_bold
|
|
# shape_literal blue
|
|
# shape_match_pattern green
|
|
# shape_matching_brackets attr u
|
|
# shape_nothing light_cyan
|
|
# shape_operator yellow
|
|
# shape_pipe purple_bold
|
|
# shape_range yellow_bold
|
|
# shape_record cyan_bold
|
|
# shape_redirection purple_bold
|
|
# shape_signature green_bold
|
|
# shape_string green
|
|
# shape_string_interpolation cyan_bold
|
|
# shape_table blue_bold
|
|
# shape_variable purple
|
|
# shape_vardecl purple
|
|
# shape_raw_string light_purple
|
|
}
|
|
|
|
${prompt}
|
|
|
|
$env.config.show_banner = false
|
|
|
|
fresh
|
|
|
|
'';
|
|
in
|
|
{
|
|
|
|
user.xdg.config.files."nushell/config.nu".source = nuConfig;
|
|
programs.command-not-found.enable = false;
|
|
programs.zoxide.enable = true;
|
|
|
|
environment.shellAliases = {
|
|
};
|
|
environment.systemPackages = [
|
|
nushell
|
|
];
|
|
environment.shells = [
|
|
nushell
|
|
];
|
|
users.defaultUserShell = nushell;
|
|
console.font = "Lat2-Terminus16";
|
|
|
|
environment.variables = {
|
|
EDITOR = "hx";
|
|
};
|
|
|
|
}
|