This commit is contained in:
Thomas Forgione 2023-11-13 10:59:32 +01:00
parent e9bf3e7a17
commit 44ca3a9b5a
10 changed files with 230 additions and 230 deletions

View File

@ -1,233 +1,11 @@
source ~/.config/nushell/init.nu
# Change default config
$env.config.keybindings = (echo $env.config.keybindings | append {
name: newline_or_run_command_2
modifier: CONTROL
keycode: char_j
mode: emacs
event: {send: enter}
})
$env.config.show_banner = false
$env.config.use_grid_icons = false
$env.config.cursor_shape.emacs = block
$env.config.history.max_size = 1_000_000_000_000_000
$env.config.history.file_format = "sqlite"
$env.config.history.isolation = true
$env.config.filesize.metric = false
$env.config.table.mode = light
# remove extension shortcut
def rm-ext [] {
$in | path parse | udpate extension "" | get parent stem | str join "/"
}
# ls aliases
alias _ls = ls
def _ls_format_mode [mode: string] {
let chars = $mode | split chars
let r1 = if ($chars | get 0) == "r" { [(ansi yellow_bold), "r", (ansi reset)] } else { [(ansi grey), "-"] }
let w1 = if ($chars | get 1) == "w" { [(ansi red_bold), "w", (ansi reset)] } else { [(ansi grey), "-"] }
let x1 = if ($chars | get 2) == "x" { [(ansi green_bold), "x", (ansi reset)] } else { [(ansi grey), "-"] }
let r2 = if ($chars | get 3) == "r" { [(ansi yellow), "r", (ansi reset)] } else { [(ansi grey), "-"] }
let w2 = if ($chars | get 4) == "w" { [(ansi red), "w"] } else { [(ansi grey), "-"] }
let x2 = if ($chars | get 5) == "x" { [(ansi green), "x"] } else { [(ansi grey), "-"] }
let r3 = if ($chars | get 6) == "r" { [(ansi yellow), "r", (ansi reset)] } else { [(ansi grey), "-"] }
let w3 = if ($chars | get 7) == "w" { [(ansi red), "w"] } else { [(ansi grey), "-"] }
let x3 = if ($chars | get 8) == "x" { [(ansi green), "x"] } else { [(ansi grey), "-"] }
[$r1, $w1, $x1, $r2, $w2, $x2, $r3, $w3, $x3] | each { $in | str join } | str join
}
def l [dir?: string] {
let output = _ls (if $dir == null { "" } else { $dir }) | sort-by type name -i
if ($output | length) == 0 { "" | cat } else { $output | grid -c -s " " | cat }
}
def ls [dir?: string] {
let output = _ls (if $dir == null { "" } else { $dir }) | sort-by type name -i
if ($output | length) == 0 { "" | cat } else { $output | grid -c -s " " | cat }
}
def la [dir?: string] {
_ls -al (if $dir == null { "" } else { $dir })
| sort-by type name -i
| each { $in | update mode (_ls_format_mode $in.mode) }
| select mode name target user size modified
}
def ll [dir?: string] {
_ls -l (if $dir == null { "" } else { $dir })
| each { $in | update mode (_ls_format_mode $in.mode) }
| sort-by type name -i
| select mode name target user size modified
}
# cool du (don't display everything)
alias _du = du
def du [...args] {
let parsed_args = if ($args | is-empty) { ["*"] } else { $args }
$parsed_args | each { _du -a $in | select path apparent physical } | flatten
}
# cool df
def df [] {
^df -h
| str replace "Sys. de fichiers" "@"
| str replace "Monté sur" "@"
| detect columns
| rename "Sys. de fichiers" "Taille" "Utilisé" "Dispo" "Uti%" "Monté sur"
}
# easy markdown formamtter
def to-md [] {
let arg = $in
$env.config.table.mode = markdown;
echo $arg
}
# vim aliases
alias v = nvim
# git aliases
alias g = git
alias ga = git add
alias gaa = git add --all
alias gco = git checkout
alias gcb = git checkout -b
alias gc = git commit --verbose
alias gca = git commit --verbose --all
alias gd = git diff
alias glog = git log --oneline --decorate --graph
alias gl = git pull
alias gp = git push
alias gst = git status
alias gs = git status
def gpsup [] { git push --set-upstream origin (git rev-parse --abbrev-ref HEAD) }
# ssh completion
def _ssh_hosts [] {
open ~/.ssh/config
| lines
| find -ir "host "
| each { $in | split row " " | get 1 }
}
export extern "ssh" [
host?: string@_ssh_hosts
]
# update completion
def _update_args [] {
[
system
rust
wasm
npm
dotfiles
neovim
check
startup
last-update
postpone
force-unlock
]
}
def u [arg?: string@_update_args] {
if $arg == null {
^update
} else {
^update $arg
}
}
# gclone aliases
def _gclone_dirs [] {
let slashes = ($env.GCLONE_PATH | split row "/" | length) + 2
open ([$env.GCLONE_PATH, .cdgcache] | path join)
| lines
| where { ($in | split row "/" | length) >= $slashes }
| each { $in | split row "/" | last }
| sort
| uniq
}
def-env cdg [key: string@_gclone_dirs] { cd (CLICOLOR_FORCE=1 pgd $key) }
# pass aliases / completion
def _pass_completion [] {
_ls ~/.password-store/**/* | each { |x|
if $x.type == "file" {
$x.name
| path parse
| update extension ""
| get parent stem
| str join "/"
} else {
$x.name + "/"
}
| split row '/'
| skip 4
| str join "/"
}
| prepend git
| prepend insert
}
export extern "pass" [ host?: string@_pass_completion ]
def p [ arg: string@_pass_completion ] { pass $arg }
def pc [ arg: string@_pass_completion ] { pass --clip $arg }
# docker aliases
alias ld = lazydocker
alias dc = docker-compose
alias dcb = docker-compose build
def dcp [] { docker-compose build; docker-compose push }
alias dcu = docker-compose up -d --build --remove-orphans
alias dcd = docker-compose down
def dcr [] { docker-compose down; docker-compose up -d --build --remove-orphans }
# kubernetes aliases
$env.KUBECONFIG = if ([$env.HOME, .kubes, current-cube] | path join | path exists) {
open ([$env.HOME, .kubes, current-cube] | path join)
} else {
""
}
def _kube_kubes [] {
_ls ~/.kubes | where type == dir | get name | path basename
}
def-env kube [name?: string@_kube_kubes] {
use assert
let kubes_path = [$env.HOME, .kubes] | path join
if $name == null {
rm ([$kubes_path, current-cube] | path join)
$env.KUBECONFIG = ""
return
}
let kube_config = [$kubes_path, $name, config] | path join
if not ($kube_config | path exists) {
error make {msg: ($kube_config + " does not exist")}
}
$kube_config | save -f ([$kubes_path, current-cube] | path join)
$env.KUBECONFIG = $kube_config
}
alias kns = k9s
# Useful aliases
alias :q = exit
alias pdf = evince
alias rg = rg -uu
def-env mkcd [dir: string] { mkdir $dir; cd $dir }
source ~/.config/nushell/config/init.nu
source ~/.config/nushell/config/config.nu
source ~/.config/nushell/config/aliases.nu
source ~/.config/nushell/config/git.nu
source ~/.config/nushell/config/update.nu
source ~/.config/nushell/config/gclone.nu
source ~/.config/nushell/config/pass.nu
source ~/.config/nushell/config/docker.nu
# Start tfetch
tfetch

75
nushell/config/aliases.nu Normal file
View File

@ -0,0 +1,75 @@
# remove extension shortcut
def rm-ext [] {
$in | path parse | udpate extension "" | get parent stem | str join "/"
}
# ls aliases
alias _ls = ls
def _ls_format_mode [mode: string] {
let chars = $mode | split chars
let r1 = if ($chars | get 0) == "r" { [(ansi yellow_bold), "r", (ansi reset)] } else { [(ansi grey), "-"] }
let w1 = if ($chars | get 1) == "w" { [(ansi red_bold), "w", (ansi reset)] } else { [(ansi grey), "-"] }
let x1 = if ($chars | get 2) == "x" { [(ansi green_bold), "x", (ansi reset)] } else { [(ansi grey), "-"] }
let r2 = if ($chars | get 3) == "r" { [(ansi yellow), "r", (ansi reset)] } else { [(ansi grey), "-"] }
let w2 = if ($chars | get 4) == "w" { [(ansi red), "w"] } else { [(ansi grey), "-"] }
let x2 = if ($chars | get 5) == "x" { [(ansi green), "x"] } else { [(ansi grey), "-"] }
let r3 = if ($chars | get 6) == "r" { [(ansi yellow), "r", (ansi reset)] } else { [(ansi grey), "-"] }
let w3 = if ($chars | get 7) == "w" { [(ansi red), "w"] } else { [(ansi grey), "-"] }
let x3 = if ($chars | get 8) == "x" { [(ansi green), "x"] } else { [(ansi grey), "-"] }
[$r1, $w1, $x1, $r2, $w2, $x2, $r3, $w3, $x3] | each { $in | str join } | str join
}
def l [dir?: string] {
let output = _ls (if $dir == null { "" } else { $dir }) | sort-by type name -i
if ($output | length) == 0 { "" | cat } else { $output | grid -c -s " " | cat }
}
def ls [dir?: string] {
let output = _ls (if $dir == null { "" } else { $dir }) | sort-by type name -i
if ($output | length) == 0 { "" | cat } else { $output | grid -c -s " " | cat }
}
def la [dir?: string] {
_ls -al (if $dir == null { "" } else { $dir })
| sort-by type name -i
| each { $in | update mode (_ls_format_mode $in.mode) }
| select mode name target user size modified
}
def ll [dir?: string] {
_ls -l (if $dir == null { "" } else { $dir })
| each { $in | update mode (_ls_format_mode $in.mode) }
| sort-by type name -i
| select mode name target user size modified
}
# cool du (don't display everything)
alias _du = du
def du [...args] {
let parsed_args = if ($args | is-empty) { ["*"] } else { $args }
$parsed_args | each { _du -a $in | select path apparent physical } | flatten
}
# cool df
def df [] {
^df -h
| str replace "Sys. de fichiers" "@"
| str replace "Monté sur" "@"
| detect columns
| rename "Sys. de fichiers" "Taille" "Utilisé" "Dispo" "Uti%" "Monté sur"
}
# easy markdown formamtter
def to-md [] {
let arg = $in
$env.config.table.mode = markdown;
echo $arg
}
# Useful aliases
alias v = nvim
alias :q = exit
alias pdf = evince
alias rg = rg -uu
def-env mkcd [dir: string] { mkdir $dir; cd $dir }

17
nushell/config/config.nu Normal file
View File

@ -0,0 +1,17 @@
# Change default config
$env.config.keybindings = (echo $env.config.keybindings | append {
name: newline_or_run_command_2
modifier: CONTROL
keycode: char_j
mode: emacs
event: {send: enter}
})
$env.config.show_banner = false
$env.config.use_grid_icons = false
$env.config.cursor_shape.emacs = block
$env.config.history.max_size = 1_000_000_000_000_000
$env.config.history.file_format = "sqlite"
$env.config.history.isolation = true
$env.config.filesize.metric = false
$env.config.table.mode = light

43
nushell/config/docker.nu Normal file
View File

@ -0,0 +1,43 @@
# docker aliases
alias ld = lazydocker
alias dc = docker-compose
alias dcb = docker-compose build
def dcp [] { docker-compose build; docker-compose push }
alias dcu = docker-compose up -d --build --remove-orphans
alias dcd = docker-compose down
def dcr [] { docker-compose down; docker-compose up -d --build --remove-orphans }
# kubernetes aliases
$env.KUBECONFIG = if ([$env.HOME, .kubes, current-cube] | path join | path exists) {
open ([$env.HOME, .kubes, current-cube] | path join)
} else {
""
}
def _kube_kubes [] {
_ls ~/.kubes | where type == dir | get name | path basename
}
def-env kube [name?: string@_kube_kubes] {
use assert
let kubes_path = [$env.HOME, .kubes] | path join
if $name == null {
rm ([$kubes_path, current-cube] | path join)
$env.KUBECONFIG = ""
return
}
let kube_config = [$kubes_path, $name, config] | path join
if not ($kube_config | path exists) {
error make {msg: ($kube_config + " does not exist")}
}
$kube_config | save -f ([$kubes_path, current-cube] | path join)
$env.KUBECONFIG = $kube_config
}
alias kns = k9s

13
nushell/config/gclone.nu Normal file
View File

@ -0,0 +1,13 @@
# gclone aliases
def _gclone_dirs [] {
let slashes = ($env.GCLONE_PATH | split row "/" | length) + 2
open ([$env.GCLONE_PATH, .cdgcache] | path join)
| lines
| where { ($in | split row "/" | length) >= $slashes }
| each { $in | split row "/" | last }
| sort
| uniq
}
def-env cdg [key: string@_gclone_dirs] { cd (CLICOLOR_FORCE=1 pgd $key) }

15
nushell/config/git.nu Normal file
View File

@ -0,0 +1,15 @@
# git aliases
alias g = git
alias ga = git add
alias gaa = git add --all
alias gco = git checkout
alias gcb = git checkout -b
alias gc = git commit --verbose
alias gca = git commit --verbose --all
alias gd = git diff
alias glog = git log --oneline --decorate --graph
alias gl = git pull
alias gp = git push
alias gst = git status
alias gs = git status
def gpsup [] { git push --set-upstream origin (git rev-parse --abbrev-ref HEAD) }

24
nushell/config/pass.nu Normal file
View File

@ -0,0 +1,24 @@
# pass aliases / completion
def _pass_completion [] {
_ls ~/.password-store/**/* | each { |x|
if $x.type == "file" {
$x.name
| path parse
| update extension ""
| get parent stem
| str join "/"
} else {
$x.name + "/"
}
| split row '/'
| skip 4
| str join "/"
}
| prepend git
| prepend insert
}
export extern "pass" [ host?: string@_pass_completion ]
def p [ arg: string@_pass_completion ] { pass $arg }
def pc [ arg: string@_pass_completion ] { pass --clip $arg }

11
nushell/config/ssh.nu Normal file
View File

@ -0,0 +1,11 @@
# ssh completion
def _ssh_hosts [] {
open ~/.ssh/config
| lines
| find -ir "host "
| each { $in | split row " " | get 1 }
}
export extern "ssh" [
host?: string@_ssh_hosts
]

24
nushell/config/update.nu Normal file
View File

@ -0,0 +1,24 @@
# update completion
def _update_args [] {
[
system
rust
wasm
npm
dotfiles
neovim
check
startup
last-update
postpone
force-unlock
]
}
def u [arg?: string@_update_args] {
if $arg == null {
^update
} else {
^update $arg
}
}