Comments (5)
Hi acrisci,
As far as I know, there is no way to change the working directory without using the shell built-in command cd
. And the only way to call cd
in your current process is to do it "through the shell" (e.g. alias, function). In other words, there is no way to achieve this with a python (or any other) executable. We would have to use a shell script instead. Even if we did have this d
shell script, in order to add it to PATH would still result in the user having to add a line in his/her runtime configuration (not 100% sure). If you can find a way to avoid this I would be more than happy to consider it.
Jay
from dtags.
I didn't think of that. It turns out you are correct.
There is another way that might be a bit cleaner though. You can also change directories by source
ing a shell script that changes directories. So for instance, if chdir.sh
contains
cd $1
I can do source chdir.sh ./some-dir
to go to the directory. So an alternative to the shell-specific eval, you could distribute /usr/bin/dtags-chdir.sh
:
cd $(/usr/bin/dtags-chdir.py $1)
Where dtags-chdir.py
is a python script that will echo where to go based on the input.
The benefit of that would be that you could put all your logic in the python script to avoid repeating your logic in many different places. It also has the benefit of simplifying the instructions to telling people to put this in their shellrc file:
alias d="source /usr/bin/dtags-chdir.sh"
for every shell (including the ones you don't support now). Backwards compatability could be achieved by evaling that alias when dtags shell [shell]
is evoked.
This is just a thought on how to make things easier. If you like things the way they are, that's fine :).
from dtags.
First of all thanks a lot for all your input. I really appreciate it.
I have considered what you are suggesting (a shell function/script piggybacking on a python executable) in the past, and you are right it definitely has its advantages. The only thing I didn't like about the approach was the fact the python interpreter would be invoked every single time. I've actually tested both methods and as small as it may be, I noticed a small difference in speed (especially on slow VMs). I decided to sacrifice a little bit of convenience during set up in exchange for better overall performance. In fact, in the future I may leave Python altogether and convert the whole tool into a set of shell functions for this very reason.
from dtags.
That is actually a good point. Every milisecond counts when running a command like cd
and I'm sure I would notice the difference.
There can be a solution to that, however, that you should consider before you ditch python. It is possible to compile the python files so that they load faster. You should see a big difference in startup times. Whether or not that's good enough I'll leave up to you.
https://docs.python.org/release/1.5.1p1/tut/node43.html
from dtags.
The conversion will probably take a lot research and time to carry out. So it won't happen any time soon, if at all. I've never considered .pyo files. I will try it out when I have time. Thanks!
from dtags.
Related Issues (18)
- feature idea - support folders mounted over `ssh` / via `sshfs` HOT 2
- Quieter directory command HOT 3
- Refactor scripts into template files HOT 2
- Command to make other commands work with dtags HOT 3
- Only alphabets and the underscore character are now allowed in tag names HOT 8
- Problem about dtags HOT 6
- support tagging of paths containing `#` HOT 1
- Unable to make it work HOT 6
- Needs clarification for Windows users HOT 2
- `run`: can it be made to run in the context of $whoami's $SHELL + .rc file? HOT 2
- d "directory" giving errors HOT 3
- Feat request: Allow "chaining" of commands
- dtags edit throws traceback HOT 5
- TypeError: a bytes-like object is required, not 'str' HOT 4
- d label not working properly HOT 10
- all commads can be used normally,but when use 'd' with error: command not found HOT 10
- Getting error "Invalid argument: -10" when using on OSX with ohmyzshell HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dtags.