Replies: 1 comment
-
This is one of the weaknesses of nushell for which i have not found a perfect workaround (but maybe someone else has): you cant export aliases, etc in closures due to the scope:
(not just functions, but also a way to circumvent the scope problem is by writing it into a script and then using the workaround within the context of a config file for this is by creating a temporary script file in
open -r ~/.bashrc
| lines
| parse -r "^[ \t]*alias (?P<from>[^=]+)=(?P<to>.*)$"
| each {|i| $"alias ($i.from) = do ($i.to)"}
| prepend "export-env {"
| append "}"
| str join "\n"
| save -rf /tmp/bash_alias_export_to.nu
use /tmp/bash_alias_export_to.nu and the only workaround im aware of for other scripts is by generating a script containing everything the script intends to do inside of a string and then executing the string in its own context using nu -c (
open -r ~/.bashrc
| lines
| parse -r "^[ \t]*alias (?P<from>[^=]+)=(?P<to>.*)$"
| each {|i| $"alias ($i.from) = do ($i.to)"}
| append "some other command"
| str join "\n"
) altough id recommend using custom aliases for nushell (at least for the most part). or what i do with other programs: maintain a open ./keybinds.csv
| where nvim == "true"
| each {|i|
$"map\(\"($i.mode)\", \"($i.key)\", \"($i.action)\");"
}
| prepend "#include \"./nvim.h\"\nint luaopen_config_keybinds() {"
| append 'return 1;}'
| str join "\n"
| save -r src/keybinds.c
^gcc -o lua/config/keybinds.so -std=gnu11 -O2 src/keybinds.c -shared -fPIC
rm src/keybinds.c |
Beta Was this translation helpful? Give feedback.
-
Similar to the pattern in #4103, I am trying to let bash parse my aliases file then load it into Nushell. This is what I have:
However,
$x.k
flags with "alias name can't be a number, a filesize, or contain a hash # or caret ^" (none of these apply). Changing$x.k
to a fixed string for testing completes successfully, but does not set the alias.Is there a better way to do this?
Beta Was this translation helpful? Give feedback.
All reactions