Crates.io | nu-alias-converter |
lib.rs | nu-alias-converter |
version | 0.1.3 |
source | src |
created_at | 2024-10-17 15:30:45.890514 |
updated_at | 2024-10-17 15:53:23.590425 |
description | Converts Bash aliases to Nushell |
homepage | |
repository | https://github.com/marcelarie/nu-alias-converter |
max_upload_size | |
id | 1413356 |
size | 1,231,246 |
[!NOTE]
This project is for educational purposes. I aim to learn more about tree-sitter, parsing, and Rust.
cargo install nu-alias-converter
The main purpose of this tool is to convert Bash aliases to Nushell aliases. This can be done with this simple command:
nu-alias-converter .bash_aliases # will generate a bash-aliases.nu file in the same directory
but the best use case is to use it in the Nushell environment. This way, the file will be regenerated at the start of each shell session, so you will always be on sync with your Bash aliases.
Add this to the end of your env.nu
file (find it by running $nu.env-path
in Nushell):
# This command will be shorter in the future, I promise
nu-alias-converter ~/.bash_aliases -o $"($nu.default-config-dir)/bash-alises.nu" | ignore
Now add this to your config.nu
to source the generated aliases file (find the path
with nu.config-path
):
source bash_aliases.nu
This will make the bash aliases available in the Nushell environment.
Sometimes there are some aliases that you don't want to convert to Nushell, maybe because they are not valid or you don't want to use them in Nushell.
You can ignore aliases by adding them to a .aliasignore
file in the root of
your home directory or in the nushell config directory.
The file should contain all the aliases that should be ignored, one per line:
# ~/.aliasignore
ls
la
gst
This will not convert any of those aliases to nushell.
Another option is to ignore all the aliases that use a command, the syntax would
be the same but with a bang (!
) in front of the command name:
# ~/.aliasignore
la
gst
!ls
!htop
This will also ignore all the aliases that use ls
and htop
.
The CLI app will be written in Rust, needs to be to use the nushell crates used for parsing. It will use treesitter to parse the bash script and get all the aliases.
The aliases will then be converted to the nushell format using the nu-parser crate. After converting, the aliases will be validated, if an alias is not valid it will be generated as a comment with the information of the parsing error. So the user can check it and fix it manually. It would be nice to auto generate the rust code from the content of the alias is the parsing fails but this is not a priority for now.
The converted aliases are written to a file. You can either generate them manually or use the Nushell environment. If using the environment method, the file will regenerate at the start of each shell session.
Unnecessary diagram:
Not that complex but I always wanted to try this out.
---
config:
theme: dark
look: classic
layout: dagre
---
graph TD
A[CLI App in Rust] --> K[Read .aliasignore file]
A --> B[Parse Bash with Tree-sitter]
K --> L[Should ignore alias?]
B --> L
L -->|No| C[Convert to Nushell format]
L -->|Yes| M[Skip alias]
C --> D[Validate Alias Syntax]
D --> E[Write Valid Aliases to Nushell File]
E --> F[Manual Method]
E --> G[Nushell Environment Method]
G --> H[Regenerate File at Each Shell Session]
D --> I[Comment Out Invalid Aliases]
I --> J[Include Parsing Error Information]
TODO:
Parsing Bash Aliases
expand_aliases
and shopt -s expand_aliases
Conversion to Nushell Format
File Handling
env.nu
.alias_ignore
file to skip certain aliases during conversion
Flags and Modes
--help
flag--no-comments
flag*.nu
files error--output
flag to specify the output file path and namePerformance