mirror of
https://github.com/elwrcl/copnix.git
synced 2026-10-31 14:28:02 +03:00
nu
This commit is contained in:
10 files changed
+9
-9
No files matched your search
@@ -0,0 +1,38 @@
|
||||
{ ... }:
|
||||
{
|
||||
flake.homeModules.home-nushell-bash-compat =
|
||||
{ ... }:
|
||||
{
|
||||
programs.nushell.extraConfig = ''
|
||||
$env.DIRSTACK = []
|
||||
def --env pushd [path: path] {
|
||||
$env.DIRSTACK = ($env.DIRSTACK | prepend $env.PWD)
|
||||
cd $path
|
||||
}
|
||||
|
||||
def --env popd [] {
|
||||
if ($env.DIRSTACK | is-empty) {
|
||||
print $"(ansi red)popd: directory stack empty(ansi reset)"
|
||||
} else {
|
||||
let top = ($env.DIRSTACK | first)
|
||||
$env.DIRSTACK = ($env.DIRSTACK | skip 1)
|
||||
cd $top
|
||||
}
|
||||
}
|
||||
|
||||
def dirs [] {
|
||||
[$env.PWD] | append $env.DIRSTACK
|
||||
}
|
||||
|
||||
def bashc [command: string] {
|
||||
^bash -lc $command
|
||||
}
|
||||
|
||||
def rerun [] {
|
||||
let last = (history | last | get command)
|
||||
print $"(ansi grey)$ ($last)(ansi reset)"
|
||||
^bash -lc $last
|
||||
}
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
{ ... }:
|
||||
{
|
||||
flake.homeModules.home-nushell-colors =
|
||||
{ pkgs, lib, ... }:
|
||||
let
|
||||
inherit (lib.meta) getExe;
|
||||
|
||||
lsColors = pkgs.runCommand "ls_colors.txt" { } ''
|
||||
${getExe pkgs.vivid} generate gruvbox-dark-hard > $out
|
||||
'';
|
||||
in
|
||||
{
|
||||
home.packages = [ pkgs.vivid ];
|
||||
|
||||
programs.nushell.extraConfig = ''
|
||||
$env.LS_COLORS = open --raw ${lsColors}
|
||||
|
||||
$env.config.color_config.row_index = "light_yellow_bold"
|
||||
$env.config.color_config.header = "light_yellow_bold"
|
||||
|
||||
$env.config.color_config.bool = {||
|
||||
if $in {
|
||||
"light_green_bold"
|
||||
} else {
|
||||
"light_red_bold"
|
||||
}
|
||||
}
|
||||
|
||||
$env.config.color_config.string = {||
|
||||
if $in =~ "^(#|0x)[a-fA-F0-9]+$" {
|
||||
$in | str replace "0x" "#"
|
||||
} else {
|
||||
"white"
|
||||
}
|
||||
}
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
{ ... }:
|
||||
{
|
||||
flake.homeModules.home-nushell-commandline-copy =
|
||||
{ pkgs, lib, ... }:
|
||||
let
|
||||
inherit (lib.meta) getExe';
|
||||
wlCopy = getExe' pkgs.wl-clipboard "wl-copy";
|
||||
in
|
||||
{
|
||||
home.packages = [ pkgs.wl-clipboard ];
|
||||
|
||||
programs.nushell.extraConfig = ''
|
||||
def nu-highlight-default [] {
|
||||
let input = $in
|
||||
$env.config.color_config = {}
|
||||
$input | nu-highlight
|
||||
}
|
||||
|
||||
def "nu-keybind commandline-copy" []: nothing -> nothing {
|
||||
commandline
|
||||
| nu-highlight-default
|
||||
| [ "```ansi" $in "```" ]
|
||||
| str join (char nl)
|
||||
| ^${wlCopy}
|
||||
}
|
||||
|
||||
$env.config.keybindings ++= [
|
||||
{
|
||||
name: copy_color_commandline
|
||||
modifier: control_alt
|
||||
keycode: char_c
|
||||
mode: [ emacs vi_insert vi_normal ]
|
||||
event: {
|
||||
send: executehostcommand
|
||||
cmd: 'nu-keybind commandline-copy'
|
||||
}
|
||||
}
|
||||
]
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
{ ... }:
|
||||
{
|
||||
flake.homeModules.home-nushell-completions =
|
||||
{ pkgs, lib, ... }:
|
||||
let
|
||||
inherit (lib.meta) getExe;
|
||||
|
||||
carapaceNu = pkgs.runCommand "carapace.nu" { } ''
|
||||
${getExe pkgs.carapace} _carapace nushell > $out
|
||||
'';
|
||||
in
|
||||
{
|
||||
home.packages = [ pkgs.carapace ];
|
||||
|
||||
programs.nushell.environmentVariables.CARAPACE_BRIDGES = "zsh,fish,bash";
|
||||
|
||||
programs.nushell.extraConfig = ''
|
||||
let menus = [
|
||||
{
|
||||
name: completion_menu
|
||||
only_buffer_difference: false
|
||||
marker: ($env.PROMPT_INDICATOR? | default "> ")
|
||||
type: {
|
||||
layout: ide
|
||||
min_completion_width: 0
|
||||
max_completion_width: 150
|
||||
max_completion_height: 25
|
||||
padding: 0
|
||||
border: false
|
||||
cursor_offset: 0
|
||||
description_mode: "prefer_right"
|
||||
min_description_width: 0
|
||||
max_description_width: 50
|
||||
max_description_height: 10
|
||||
description_offset: 1
|
||||
correct_cursor_pos: true
|
||||
}
|
||||
style: {
|
||||
text: white
|
||||
selected_text: white_reverse
|
||||
description_text: yellow
|
||||
match_text: { attr: u }
|
||||
selected_match_text: { attr: ur }
|
||||
}
|
||||
}
|
||||
{
|
||||
name: history_menu
|
||||
only_buffer_difference: true
|
||||
marker: ($env.PROMPT_INDICATOR? | default "> ")
|
||||
type: {
|
||||
layout: list
|
||||
page_size: 10
|
||||
}
|
||||
style: {
|
||||
text: white
|
||||
selected_text: white_reverse
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
$env.config.menus = $env.config.menus
|
||||
| where name not-in ($menus | get name)
|
||||
| append $menus
|
||||
|
||||
source ${carapaceNu}
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
{ ... }:
|
||||
{
|
||||
flake.homeModules.home-nushell-editor =
|
||||
{ ... }:
|
||||
{
|
||||
programs.nushell = {
|
||||
environmentVariables = {
|
||||
EDITOR = "hx";
|
||||
VISUAL = "hx";
|
||||
};
|
||||
|
||||
shellAliases = {
|
||||
e = "hx";
|
||||
cop = "ide ~/copland";
|
||||
};
|
||||
#/nu/#
|
||||
extraConfig = ''
|
||||
def hxf [] {
|
||||
let picked = (
|
||||
do {
|
||||
fd --type f --hidden --exclude .git
|
||||
| fzf --preview 'bat --color=always --style=numbers {}'
|
||||
} | complete
|
||||
)
|
||||
|
||||
if $picked.exit_code != 0 { return }
|
||||
|
||||
let file = ($picked.stdout | str trim)
|
||||
if ($file | is-not-empty) { hx $file }
|
||||
}
|
||||
|
||||
def hxd [rev: string = "@"] {
|
||||
let files = (
|
||||
jj diff --revision $rev --name-only
|
||||
| lines
|
||||
| where { |line| ($line | str trim) != "" }
|
||||
)
|
||||
|
||||
if ($files | is-empty) {
|
||||
print $"(ansi yellow)($rev) no changes (ansi reset)"
|
||||
return
|
||||
}
|
||||
|
||||
hx ...$files
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
{ ... }:
|
||||
{
|
||||
flake.homeModules.home-nushell-keybinds =
|
||||
{ ... }:
|
||||
{
|
||||
programs.nushell.extraConfig = ''
|
||||
$env.config.keybindings ++= [
|
||||
{
|
||||
name: jj_status
|
||||
modifier: alt
|
||||
keycode: char_s
|
||||
mode: [ emacs vi_insert vi_normal ]
|
||||
event: { send: executehostcommand, cmd: "jj status" }
|
||||
}
|
||||
{
|
||||
name: jj_log
|
||||
modifier: alt
|
||||
keycode: char_l
|
||||
mode: [ emacs vi_insert vi_normal ]
|
||||
event: { send: executehostcommand, cmd: "jj log" }
|
||||
}
|
||||
{
|
||||
name: jj_diff
|
||||
modifier: alt
|
||||
keycode: char_d
|
||||
mode: [ emacs vi_insert vi_normal ]
|
||||
event: { send: executehostcommand, cmd: "jj diff" }
|
||||
}
|
||||
]
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{ ... }:
|
||||
{
|
||||
flake.homeModules.home-nushell-last =
|
||||
{ ... }:
|
||||
{
|
||||
programs.nushell.extraConfig = ''
|
||||
$env.config.hooks.display_output = {||
|
||||
tee { table --expand | print }
|
||||
# SQLiteDatabase doesn't support equality comparisons.
|
||||
| try { if $in != null { $env.last = $in } }
|
||||
}
|
||||
|
||||
# Retrieve the output of the last command.
|
||||
def _ []: nothing -> any {
|
||||
$env.last?
|
||||
}
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
{ ... }:
|
||||
{
|
||||
flake.homeModules.home-nushell-prompt =
|
||||
{ ... }:
|
||||
{
|
||||
programs.nushell.extraConfig = ''
|
||||
do --env {
|
||||
use std null_device
|
||||
|
||||
def prompt-header [
|
||||
--left-char: string
|
||||
]: nothing -> string {
|
||||
let code = $env.LAST_EXIT_CODE
|
||||
|
||||
let jj_workspace_root = try {
|
||||
jj workspace root err> $null_device
|
||||
} catch {
|
||||
""
|
||||
}
|
||||
|
||||
let hostname = if ($env.SSH_CONNECTION? | is-not-empty) {
|
||||
$"(ansi light_green_bold)@(sys host | get hostname)(ansi reset) "
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
||||
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 {
|
||||
$"($hostname)(ansi cyan)(
|
||||
if (pwd | str starts-with $env.HOME) {
|
||||
"~" | path join (pwd | path relative-to $env.HOME)
|
||||
} else {
|
||||
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 = {||
|
||||
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> $null_device
|
||||
} catch {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
$env.TRANSIENT_PROMPT_INDICATOR = " "
|
||||
$env.TRANSIENT_PROMPT_INDICATOR_VI_INSERT = $env.TRANSIENT_PROMPT_INDICATOR
|
||||
$env.TRANSIENT_PROMPT_INDICATOR_VI_NORMAL = $env.TRANSIENT_PROMPT_INDICATOR
|
||||
$env.TRANSIENT_PROMPT_MULTILINE_INDICATOR = $env.TRANSIENT_PROMPT_INDICATOR
|
||||
$env.TRANSIENT_PROMPT_COMMAND = {||
|
||||
prompt-header --left-char "━"
|
||||
}
|
||||
$env.TRANSIENT_PROMPT_COMMAND_RIGHT = $env.PROMPT_COMMAND_RIGHT
|
||||
}
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
{ ... }:
|
||||
{
|
||||
flake.homeModules.home-nushell =
|
||||
{ ... }:
|
||||
{
|
||||
programs.nushell = {
|
||||
enable = true;
|
||||
|
||||
shellAliases = {
|
||||
ls = "eza --icons --group-directories-first";
|
||||
ll = "eza -lah --icons --group-directories-first";
|
||||
la = "eza -a --icons --group-directories-first";
|
||||
lt = "eza --tree --level=2 --icons";
|
||||
tree = "eza --tree --git-ignore --group-directories-first";
|
||||
|
||||
cat = "bat";
|
||||
df = "^df -h";
|
||||
du = "^du -h";
|
||||
free = "^free -h";
|
||||
rm = "trash-put";
|
||||
|
||||
sysinfo = "fastfetch";
|
||||
monitor = "sudo btop";
|
||||
ports = "sudo ss -tulpn";
|
||||
myip = "curl ifconfig.me";
|
||||
|
||||
js = "jj status";
|
||||
jl = "jj log";
|
||||
jd = "jj diff";
|
||||
jc = "jj commit";
|
||||
jp = "jj git push";
|
||||
jf = "jj git fetch";
|
||||
|
||||
gs = "git status";
|
||||
ga = "git add";
|
||||
gp = "git push";
|
||||
gl = "git log --oneline --graph --decorate";
|
||||
|
||||
#gnu
|
||||
gfind = "^find";
|
||||
ggrep = "^grep --color=auto";
|
||||
gls = "^ls";
|
||||
gdu = "^du";
|
||||
gmkdir = "^mkdir";
|
||||
|
||||
".." = "cd ..";
|
||||
"..." = "cd ../..";
|
||||
"...." = "cd ../../..";
|
||||
};
|
||||
|
||||
environmentVariables = {
|
||||
MESA_SHADER_CACHE_MAX_SIZE = "2G";
|
||||
MESA_SHADER_CACHE_DIR = "/tmp/mesa_shader_cache";
|
||||
FZF_DEFAULT_OPTS = "--height 40% --layout=reverse --border";
|
||||
FZF_DEFAULT_COMMAND = "fd --type f --hidden --follow --exclude .git";
|
||||
};
|
||||
|
||||
extraEnv = ''
|
||||
$env.PATH = ($env.PATH | prepend $"($env.HOME)/.local/bin")
|
||||
'';
|
||||
|
||||
extraConfig = ''
|
||||
$env.config.show_banner = false
|
||||
$env.config.history.file_format = "sqlite"
|
||||
$env.config.history.max_size = 1_000_000
|
||||
$env.config.history.isolation = false
|
||||
|
||||
$env.config.edit_mode = "vi"
|
||||
$env.config.cursor_shape.vi_insert = "line"
|
||||
$env.config.cursor_shape.vi_normal = "block"
|
||||
|
||||
$env.config.completions.algorithm = "substring"
|
||||
$env.config.highlight_resolved_externals = true
|
||||
|
||||
def --env mc [path: path] {
|
||||
mkdir $path
|
||||
cd $path
|
||||
}
|
||||
|
||||
def --env mcg [path: path] {
|
||||
mkdir $path
|
||||
cd $path
|
||||
jj git init --colocate
|
||||
}
|
||||
|
||||
def rebuild [] {
|
||||
jj --repository ~/copland status | ignore
|
||||
nh os switch --accept-flake-config
|
||||
}
|
||||
|
||||
def rebuild-dry [] {
|
||||
nh os switch --dry --accept-flake-config
|
||||
}
|
||||
|
||||
def rebuild-up [] {
|
||||
nix flake update --flake ~/copland
|
||||
jj --repository ~/copland status | ignore
|
||||
nh os switch --accept-flake-config
|
||||
}
|
||||
|
||||
def extract [file: path] {
|
||||
let name = ($file | path basename)
|
||||
match $name {
|
||||
_ if ($name | str ends-with ".tar.bz2") => { ^tar xjf $file }
|
||||
_ if ($name | str ends-with ".tar.gz") => { ^tar xzf $file }
|
||||
_ if ($name | str ends-with ".tar.xz") => { ^tar xJf $file }
|
||||
_ if ($name | str ends-with ".tar") => { ^tar xf $file }
|
||||
_ if ($name | str ends-with ".bz2") => { ^bunzip2 $file }
|
||||
_ if ($name | str ends-with ".gz") => { ^gunzip $file }
|
||||
_ if ($name | str ends-with ".zip") => { ^unzip $file }
|
||||
_ if ($name | str ends-with ".7z") => { ^7z x $file }
|
||||
_ if ($name | str ends-with ".rar") => { ^unrar e $file }
|
||||
_ => { print $"(ansi red)'($name)' açılamıyor(ansi reset)" }
|
||||
}
|
||||
}
|
||||
|
||||
# `which`, with canonicalize .
|
||||
def realwhich [...applications: string, --all (-a)] {
|
||||
which --all=$all ...$applications
|
||||
| update path {|row|
|
||||
match $row.type {
|
||||
"external" => { $row.path | path expand }
|
||||
_ => $row.path
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($"($env.HOME)/.config/copetch/animated-copetch.sh" | path exists) {
|
||||
^$"($env.HOME)/.config/copetch/animated-copetch.sh"
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user