dotfiles
bugabingas dorkfiles
owned by bugabinga
nushell: direnv and cleanup
a60188fdd50bdda45a55e98849e9146e5ba1e090
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
Browse filesCompare with HEAD
Changed files (8)
nushell/auto-overlay.nu
Addednew file mode 100644 4 +$env.LAST_NUMODS_DIR = null
5 +$env.NU_NUMODS_OVERLAYS = []
8 +def find-numods-dir [start_dir: path] {
9 + let home = (
$env.HOME | path expand)
10 + let parts = (
$start_dir | path split)
11 + let paths = (
$parts | enumerate |
each { |it|
12 + let path = (
$parts | first (
$it.index +
1) | path join)
13 + if (
$path | path join
".numods" | path exists) {
18 + } |
where { |p|
$p != null })
20 + if (
$paths | is-empty) and (
$start_dir !=
$home) {
21 + let parent = (
$start_dir | path dirname)
22 + if (
$parent ==
$start_dir or
$parent ==
$home) {
25 + return (find-numods-dir
$parent)
28 + return (
$paths | first | default null)
32 +def load-numods [dir: path] {
33 + let numods_file = (
$dir | path join
".numods")
34 + if (not (
$numods_file | path exists)) {
35 + print $
"No .numods in ($dir). You trying to sabotage me?" 39 + let modules = (open
$numods_file | lines | str trim |
where { |m| not (
$m | is-empty) })
41 + for module
in $modules {
43 + let module_path =
if (
$module | path exists) {
46 + (
$dir | path join
$module)
48 + if (
$module_path | path exists) {
49 + source-env
$module_path 50 + let module_name = (
$module_path | path basename | str replace
".nu" "")
51 + $loaded = (
$loaded | append
$module_name)
52 + print $
"Loaded module ($module_name) from ($numods_file)" 54 + let found = (
$env.NU_LIB_DIRS? | default [] |
each { |lib_dir|
55 + let p = (
$lib_dir | path join $
"($module).nu")
56 + if (
$p | path exists) {
$p }
else { null }
57 + } |
where { |p|
$p != null } | first | default null)
58 + if (
$found | is-not-empty) {
60 + $loaded = (
$loaded | append
$module)
61 + print $
"Loaded named module ($module) from ($found)" 63 + print $
"Module ($module) not found. Check your paths, genius." 67 + print $
"Failed to load module ($module). Cursed code or bad path?" 70 + $env.NU_NUMODS_OVERLAYS =
$loaded 71 + $env.LAST_NUMODS_DIR =
$dir 75 +def unload-overlay [module_name: string] {
78 + do { overlay hide
$module_name } | ignore
79 + print $
"Unloaded module ($module_name)" 81 + print $
"Failed to unload module ($module_name). It’s haunting your shell." 86 +def unload-numods [] {
87 + if (
$env.LAST_NUMODS_DIR | is-empty) {
91 + for module
in $env.NU_NUMODS_OVERLAYS {
92 + unload-overlay
$module 94 + $env.NU_NUMODS_OVERLAYS = []
95 + $env.LAST_NUMODS_DIR = null
99 +$env.config.hooks.pre_prompt = (
$env.config.hooks.pre_prompt | default [] | append {||
100 + let current_dir = (
$env.PWD | path expand)
101 + let numods_dir = (find-numods-dir
$current_dir)
104 + if (
$numods_dir | is-not-empty) {
105 + if (
$numods_dir !=
$env.LAST_NUMODS_DIR) {
107 + load-numods
$numods_dir 109 + }
else if (
$env.LAST_NUMODS_DIR | is-not-empty) {
111 + if not (
$current_dir | str starts-with
$env.LAST_NUMODS_DIR) {
118 +$env.config.hooks.pre_prompt = (
$env.config.hooks.pre_prompt | append {||
119 + let overlays = (
$env.NU_NUMODS_OVERLAYS | str join
", ")
120 + if (
$overlays | is-not-empty) {
121 + $env.NU_OVERLAYS =
$overlays 123 + $env.NU_OVERLAYS = null
nushell/config.nu
Modified 4 - return (
$p | path expand)
12 - condition: {|before, after| (
$before !=
$after) and (
$after | path join
'.env' | path exists) }
16 - | parse --regex
'\s*(?P<key>.+?)\s*=\s*?(?P<value>.+)?\s*' 17 - | reduce --fold {} { | entry, acc|
18 - $acc | upsert
$entry.key (
$entry.value | str trim | expand-home )
27 3 use_ansi_coloring: true
45 21 shell_integration: {
48 - osc133: (
$nu.os-info.family | str contains
"unix")
24 + osc133: (
$nu.os-info.family | str contains
"unix")
51 27 buffer_editor: [
"nvim" "--clean"]
37 + if (which direnv | is-empty) {
41 + ^direnv
export json | from json | default {} | load-env
42 + if 'ENV_CONVERSIONS' in $env and
'PATH' in $env.ENV_CONVERSIONS {
43 + $env.PATH =
do $env.ENV_CONVERSIONS.PATH.from_string $env.PATH 8 8 $env.TOOLS = (
"~/Tools" | path expand)
9 9 $env.CARGO_HOME = (
"~/.cargo" | path expand )
10 10 $env.GO_HOME = (
"~/.go" | path expand )
11 -$env.BARTIB_FILE = (
$env.NOTES | path join
'timetrack.txt')
43 42 $env.TERM =
"xterm-256color" 46 -if ( not
$env.WIN32 ) {
47 - let tools_bin = (
$env.TOOLS | path join bin )
50 - split row (char esep) |
56 46 $env.LS_COLORS = (try { vivid generate alabaster_dark | into string } catch {
""})
73 63 $env.NU_LIB_DIRS = [
74 64 (
$nu.default-config-dir | path join
'scripts')
65 + (
$nu.default-config-dir | path join
'modules')
nushell/gen-aliases.nu
Modified20 -aka tree eza
'--tree' '--icons' '--git' '--all' '--long' 20 +aka tree tre
'-all' '--linecount' '--symbolic' 21 21 aka view wezterm imgcat
22 -aka list eza
'--long' '--git' 22 +aka list ls
'--long' '--all' '--du' 31 31 aka la ls
'--long' '--all' 32 -aka ll lsd
'--long' '--group-directories-first' '--classify' '--git' 33 -aka la lsd
'--long' '--almost-all' '--group-directories-first' '--classify' '--git' 38 36 aka vi nvim
'--clean' 43 39 aka userctl systemctl
'--user' 46 42 aka aes java (
$env.DOTFILES + /tools/ + aes.java)
47 -aka download java (
$env.DOTFILES + /tools/ + download.java)
48 -aka download_jar java (
$env.DOTFILES + /tools/ + download_jar.java)
nushell/scripts/direnv.nu
Deleteddeleted file mode 100644 4 - return (
$p | path expand)
12 - condition: {|before, after| (
$before !=
$after) and (
$after | path join
'.env' | path exists) }
16 - | parse --regex
'\s*(?P<key>.+?)\s*=\s*?(?P<value>.+)?\s*' 17 - | reduce --fold {} { | entry, acc|
18 - $acc | upsert
$entry.key (
$entry.value | str trim | expand-home )
27 - $env.config = (
$env.config | upsert hooks { |config|
28 - let o = (
$config | get -i hooks.env_change.PWD)
30 - let appended =
if $o == null {
nushell/scripts/packages.nu
Deleteddeleted file mode 100644 3 - --cache =
"~/.cache/packages" 4 - --packages =
"~/Tools/packages.csv" 8 - let prefix =
$prefix | path expand
9 - let packages =
$packages | path expand
10 - let packages = open --raw
$packages | from csv --separator
';' --comment
'#' --trim all
11 - let cache =
$cache | path expand
13 - rm --recursive --trash --interactive-once
$cache 18 - print $
"Downloading packages..." 19 - let $packages_file = mktemp --suffix _packages.txt --tmpdir XXX
20 - $packages | get url | save --force
$packages_file 21 - run-external dlm
'--maxConcurrentDownloads' 4 '--inputFile' $packages_file '--outputDir' $cache 23 - $packages |
each { |package|
26 - let base =
$package.url | url parse | get path | path basename
27 - let cached =
$cache | path join
$base 29 - print $
"Installing ($package.name)" 30 - if (
$cached | is-archive) {
31 - print $
"Decompressing ($package.name)..." 32 - run-external ouch decompress
'--quiet' $cached '--dir' $prefix 35 - msg: $
"The package ($package.name) does not seem to be an archive." 39 - print $
"TODO: Symlinks" 44 - [ .zip .tar.gz .tar.bz2 .tar.xz .7z ] | any { |ext|
$in | str ends-with
$ext }
47 -def remove-archive-extension [] {
49 - [ .zip .tar.gz .tar.bz2 .tar.xz .7z ] | reduce --fold
$uri { |ext, acc|
50 - $acc | str replace
$ext '' 54 -def check_dependencies [] {
55 - let missing = [ ouch dlm ] | any { which
$in | is-empty }
58 - msg:
'Some dependency is missing!' nushell/scripts/sy.nu
Modified 6 - let git_status_notes = [
'-C' $env.NOTES status ]
7 - let git_status_dotfiles = [
'-C' $env.DOTFILES status ]
6 + let git_status_notes = [
'-C' $env.NOTES status
'--short' '--branch' ]
7 + let git_status_dotfiles = [
'-C' $env.DOTFILES status
'--short' '--branch' ]
10 10 run-external git ...
$git_status_notes 21 20 let git_add_notes = [
'-C' $env.NOTES add
'--all' ]
22 21 let git_commit_notes = [
'-C' $env.NOTES commit
'--all' ]
23 - let git_push_notes = [
'-C' $env.NOTES push
'-ff' ]
22 + let git_push_notes = [
'-C' $env.NOTES push ]
24 23 let git_add_dotfiles = [
'-C' $env.DOTFILES add
'--all' ]
25 24 let git_commit_dotfiles = [
'-C' $env.DOTFILES commit
'--all' ]
26 25 let git_push_dotfiles = [
'-C' $env.DOTFILES push ]