-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[nu] finally got a good starting point for daily nu use
- Loading branch information
Showing
10 changed files
with
632 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
def conda-env [env-name: string] { | ||
let conda-info = (conda info --envs --json | from json) | ||
# had to remove extra "envs" dir | ||
# let suffix = (if $env-name == "base" {""} {(["envs" $env-name] | path join)}) | ||
let suffix = (if $env-name == "base" {""} {($env-name | path expand)}) | ||
# use custom env dir, hard-coded to choose XDG-based path | ||
# let env-dir = ([$conda-info.root_prefix $suffix] | path join) | ||
let env-prefix = ($conda-info.envs_dirs | where ('.config' in $it) | path expand) | ||
let env-dir = ([$env-prefix $suffix] | path join) | ||
let old-path = ($nu.path | str collect (path-sep)) | ||
let new-path = (if (windows?) { (conda-create-path-windows $env-dir) } { (conda-create-path-unix $env-dir) }) | ||
let new-env = [[name, value]; | ||
[CONDA_DEFAULT_ENV $env-name] | ||
[CONDA_PREFIX $env-dir] | ||
[CONDA_PROMPT_MODIFIER $"[($env-name)]"] | ||
[CONDA_SHLVL "1"] | ||
[CONDA_OLD_PATH $old-path]] | ||
|
||
$new-env | append $new-path | ||
} | ||
|
||
def conda-create-path-windows [env-dir] { | ||
# 1. Conda on Windows needs a few additional Path elements | ||
# 2. The path env var on Windows is called Path (not PATH) | ||
let env-path = [ | ||
$env-dir | ||
([$env-dir "Scripts"] | path join) | ||
([$env-dir "Library" "mingw-w64"] | path join) | ||
([$env-dir "Library" "bin"] | path join) | ||
([$env-dir "Library" "usr" "bin"] | path join) | ||
] | ||
let new-path = ([$env-path $nu.path] | flatten | str collect (path-sep)) | ||
[[name, value]; [Path $new-path]] | ||
} | ||
|
||
def conda-create-path-unix [env-dir] { | ||
let env-path = [ | ||
([$env-dir "bin"] | path join) | ||
] | ||
let new-path = ([$env-path $nu.path] | flatten | str collect (path-sep)) | ||
[[name, value]; [PATH $new-path]] | ||
} | ||
|
||
def windows? [] { | ||
(sys).host.name == "Windows" | ||
} | ||
|
||
def path-sep [] { | ||
if (windows?) { ";" } { ":" } | ||
} | ||
|
||
# find/return a conda env with the same name as the current directory | ||
def conda-env-pwd [] { | ||
pwd | path basename | each { conda-env $it } | ||
} | ||
|
||
# This will stream out a conda env, so you should pipe it into `load-env`, | ||
# e.g. `goto-conda-env my-env-name | load-env` | ||
def goto-conda-env [ | ||
env-name: string # approx name of the dir your conda env is named after (approx because `z` is used to jump there) | ||
] { | ||
z $env-name | ||
conda-env-pwd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
def conda-deactivate [] { | ||
let-env PATH = $nu.env.CONDA_OLD_PATH | ||
unlet-env CONDA_PROMPT_MODIFIER | ||
unlet-env CONDA_PREFIX | ||
unlet-env CONDA_SHLVL | ||
unlet-env CONDA_DEFAULT_ENV | ||
unlet-env CONDA_OLD_PATH | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
let-env PATH = $nu.env.CONDA_OLD_PATH | ||
unlet-env CONDA_PROMPT_MODIFIER | ||
unlet-env CONDA_PREFIX | ||
unlet-env CONDA_SHLVL | ||
unlet-env CONDA_DEFAULT_ENV | ||
unlet-env CONDA_OLD_PATH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
path = [ | ||
"/Users/pakelley/.local/share/.../bin", | ||
"/Users/pakelley/.config/doom-emacs/bin", | ||
] | ||
prompt = "\n$nu.env.CMD_DURATION_MS\nstarship prompt" | ||
startup = [ | ||
"zoxide init nushell --hook prompt | save ~/.zoxide.nu", | ||
"source ~/.zoxide.nu", | ||
"source fuzzy/fzf.nu", | ||
"source conda/conda.nu", | ||
"source conda/conda_deactivate.nu", | ||
] | ||
|
||
[env] | ||
STARSHIP_SHELL = "nushell" | ||
|
||
[line_editor] | ||
auto_add_history = true | ||
bell_style = "audible" | ||
color_mode = "enabled" | ||
completion_prompt_limit = 10 | ||
completion_type = "fuzzy" | ||
edit_mode = "vi" | ||
history_duplicates = "alwaysadd" | ||
history_ignore_space = true | ||
keyseq_timeout_ms = 500 | ||
max_history_size = 1000 | ||
tab_stop = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# fzf through shell history, typing result. | ||
# Requires `xdotool`. | ||
# To configure on iTerm, make a keybinding (presumably for C-r) whose action is "Send text with vim special chars", | ||
# and use: \u0001fzf-history --query="\u0005"\u000d | ||
# where \u0001 is for the start of a line, \u0005 is the end of a line, and \u000d is RET | ||
def fzf-history [ | ||
--query (-q): string # Optionally start with given query. | ||
] { | ||
let cmd = (history | uniq | reverse | each { echo [$it (char nl)] } | str collect | fzf --query $"($query)") | ||
osascript -e $'tell application "System Events" to keystroke "($cmd)"' | ||
} |
Oops, something went wrong.