Crates.io | teleport-dir |
lib.rs | teleport-dir |
version | 0.1.0 |
source | src |
created_at | 2022-04-11 08:02:21.323394 |
updated_at | 2022-04-11 08:02:21.323394 |
description | Simple rust command to navigate into the origin dir of a symlinked file. |
homepage | https://github.com/jascha030/teleport-dir |
repository | https://github.com/jascha030/teleport-dir |
max_upload_size | |
id | 565513 |
size | 18,351 |
Simple Rust command to navigate into the origin dir of a symlinked file.
Currently this package only has zsh shell integration.
Step 1: Install package from cargo.io
Use cargo to install the Rust crate.
cargo install teleport-dir
Step 2: Add to your ZSH config
Add the following code to your .zshrc
file, or another file in your function search path ($fpath
).
eval "$(teleport-dir init)"
This will add the td
function.
You can also give the function any other name by passing the --cmd
flag.
Below is an example where the function will be made available as symdir
.
eval "$(teleport-dir init --symdir)"
Let's say for example you use laravel/valet
or brew
to manage multiple php versions, and you need to be in the directory of the currently linked php version.
You could achieve this by (e.g.) executing the command shown below.
cd $(readlink -f /usr/local/bin/php)/../
This can be a little bit tedious or maybe hard to remember, so instead you can use:
td /usr/local/bin/php
The command checks if the path is symlinked resolves the origin, if this origin is a file it cd
s to the directory of the file. If the path is already a directory it just cd
s there.
For example when you have linked php@8.0
with HomeBrew.
All of the commands below will equate to cd /usr/local/Cellar/php@8.0/8.0.17/bin/
td /usr/local/bin/php
td /usr/local/Cellar/php@8.0/8.0.17/bin/php
td /usr/local/Cellar/php@8.0/8.0.17/bin/
This project is mainly just an excercise while I'm trying to learn Rust, and I have learned a lot by looking at other crate's I use or do similar things. When trying to solve the issue you can't change a directory in your main shell from a Rust command, I have taken a lot (or most) of the idea from looking at zoxide.
This composer package is an open-sourced software licensed under the MIT License