A kinda relevant question. I use Windows most of time. Like the author, I have bunch of CLI scripts (in Python mainly) which I put into my ~/bin/ equivalent. After setting python.exe as the default program for `.py` extension, and adding `.py` to `%pathext%`, I can now run my ~/bin/hello.py script at any path by just type `hello`, which I use hundreds of time a day. I now use Linux more and more (still a newbie) but…
> what if in future I don't want to execute my .py script with `/usr/bin/python` but `/usr/bin/nohtyp you're thinking too much, people have had that shebang for 20 years without any problems > But I really, really just want to run `hello` to call a `hello.py` script that is in my $PATH. I don't really understand why you're so adamant about this, either make a python "hello" script with a shebang or just tab complete…
Start all of your commands with a comma (2009)
41–50 of 177 posts
Re: Start all of your commands with a comma (2009)
#42Earlier quoted context omitted.
> Firstly, Linux seems to have no concept of "associated program", so you can never "just" call .py file, and let the shell to know to use python to execute it. Sure, you can chmod +x to the script, but then you have to add a shebang line directly to the script itself, which I always feel uncomfortable since it's hard-coded (what if in future I don't want to execute my .py script with `/usr/bin/python` but `/usr/bin/…
binfmt_misc is only useful for when a fileformat does not allow shebangs
Re: Start all of your commands with a comma (2009)
#43I'm curious how folks manage their important local configurations, e.g. - is your ~/bin directory a git repo? - if you git to manage your dot files, do you use hard links or soft links?
Re: Start all of your commands with a comma (2009)
#44Earlier quoted context omitted.
> what if in future I don't want to execute my .py script with `/usr/bin/python` but `/usr/bin/nohtyp you're thinking too much, people have had that shebang for 20 years without any problems > But I really, really just want to run `hello` to call a `hello.py` script that is in my $PATH. I don't really understand why you're so adamant about this, either make a python "hello" script with a shebang or just tab complete…
Tab complete does not work if the script isn't at CWD, which is the case here since all my script is at ~/bin/.
Re: Start all of your commands with a comma (2009)
#45A kinda relevant question. I use Windows most of time. Like the author, I have bunch of CLI scripts (in Python mainly) which I put into my ~/bin/ equivalent. After setting python.exe as the default program for `.py` extension, and adding `.py` to `%pathext%`, I can now run my ~/bin/hello.py script at any path by just type `hello`, which I use hundreds of time a day. I now use Linux more and more (still a newbie) but…
Linux can do this. There are probably more ways, but this is off the top of my head. Use an alias which you set up in your initialization scripts. You alias "hello" to "python3 /yada/yada/hello.py" which is essentially what Windows is doing for you behind the scenes.
Re: Start all of your commands with a comma (2009)
#46I'm curious how folks manage their important local configurations, e.g. - is your ~/bin directory a git repo? - if you git to manage your dot files, do you use hard links or soft links?
git init --bare $HOME/.config/repo
alias config='/usr/bin/git --git-dir=$HOME/.config/repo --work-tree=$HOME'
config config --local status.showUntrackedFiles no
Then I can do things like "config add", "config commit", and "config push".Re: Start all of your commands with a comma (2009)
#47A kinda relevant question. I use Windows most of time. Like the author, I have bunch of CLI scripts (in Python mainly) which I put into my ~/bin/ equivalent. After setting python.exe as the default program for `.py` extension, and adding `.py` to `%pathext%`, I can now run my ~/bin/hello.py script at any path by just type `hello`, which I use hundreds of time a day. I now use Linux more and more (still a newbie) but…
- The shebang is only specially interpreted by the Linux loader, i.e. when executing the file directly.
- You can still run it with any other interpreter in the standard way: `nohtyp ~/bin/hello`. Python comments start with `#`, so the shebang does nothing with programs expecting Python code.
- This situation (a script without an extension) is common on Linux, so Linux-aware editors understand the shebang to indicate a file type. At least, vim understands this and automatically detects a python file type without the .py extension.
I get your wish of Windows-like behaviour, and even if you might be able to conspire to have Linux behave the way you want, it's certainly not how people expect it to work, so prefer the above scheme for any software you send to others. :)
Re: Start all of your commands with a comma (2009)
#48I'm curious how folks manage their important local configurations, e.g. - is your ~/bin directory a git repo? - if you git to manage your dot files, do you use hard links or soft links?
My dotfiles/configs are a mix of the following setup on boot:
- one-way copy of config file from $repo/$path to $path (prevents apps from modifying my curated config or adding noise)
- or make it a symlink (if I want it mutable)
- or make it a bind mount (if a symlink won't work; can be a file or folder)
- or make it a one way copy but add a file watcher to copy changes back to the repo (if none of the above work. Some programs fail if the file they need is a symlink or is bind mounted)
For dotfiles using a one-way copy, whenever I change a setting I want to persist I have to manually copy or edit the original $repo/$path. I can take a diff against the repo for a hint, or use `inotifywait -r -e modify,create,delete,move . ~/.local ~/.config -m` for something new.
Not using hard links since the dotfiles are likely to be on a different filesystem (or dataset) than their target paths.
Re: Start all of your commands with a comma (2009)
#49I'm curious how folks manage their important local configurations, e.g. - is your ~/bin directory a git repo? - if you git to manage your dot files, do you use hard links or soft links?
Re: Start all of your commands with a comma (2009)
#50A kinda relevant question. I use Windows most of time. Like the author, I have bunch of CLI scripts (in Python mainly) which I put into my ~/bin/ equivalent. After setting python.exe as the default program for `.py` extension, and adding `.py` to `%pathext%`, I can now run my ~/bin/hello.py script at any path by just type `hello`, which I use hundreds of time a day. I now use Linux more and more (still a newbie) but…
It won’t directly help reach your goal, but it is semi hard-coded. The ‘correct’ (but see https://unix.stackexchange.com/a/29620 for some caveats) way to write a shebang line is
#!/usr/bin/env python
That will make it run the first python in your path.> what if in future I don't want to execute my .py script with `/usr/bin/python` but `/usr/bin/nohtyp`?).
You could create a symlink called python to /usr/bin/nohtyp on your system in a directory that’s searched before /usr/bin (e.g. by adding ~/myCommandPreferences to the front of your PATH)