Live data from Hacker News

Start all of your commands with a comma (2009)

rhodesmill.org

61–70 of 177 posts

Re: Start all of your commands with a comma (2009)

#61
post #51

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…

Others have already mentioned how to fix your problem, but I just want to mention one thing about why : On Linux (really, all platforms other than Windows), file extensions are much less of a thing; executables of any kind have no extension just the +x flag (among other things, this means you can rewrite them in another language without breaking anything). The .py extension is only relevant for modules meant to be im…

File name extensions.[1]

I'm not saying you're wrong, but let's be clear about what these are. I would point out that Linux inherited some, but not all of its naming conventions from Unix (as did macOS), but at least here, that is a secondary concern.

Carry on...

[1]: https://arstechnica.com/gadgets/2001/08/metadata/

Re: Start all of your commands with a comma (2009)

#62

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…

Your example got me thinking about the difference between how the windows shell and Unix shell is designed. Seems like the windows shell knows about extensions, whereas the Unix shell does not

That’s an interesting feature for a shell to have. Thanks!

Re: Start all of your commands with a comma (2009)

#63

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…

> 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.

There is, but not in the shell syntax. It's an application concern normally delegated to the desktop/GUI.

For shell scripts, the executable is usually declared in the script itself, by adding a Shebang and making the file executable. Think of the Shebang like a file extension of sorts.

If

  chmod +x ./malware.py
  ./malware.py
does not work, check the path the Shebang points to.

That being said, as long as an interpreter can execute the scripts as regular argument, you should be able to get this behavior also for xdg-open:

  xdg-open malware.py
if you really want to do that by default.

This should be equivalent to double-clicking file in the default file manager, IIRC (am on Mac now).

I had an alias "xop " when using Linux as my primary desktop OS.

But I only used this for data files (images, documents etc) where the default already works.

Wouldn't recommend setting an interpreter as default for executable scripts.

You might want to not execute scripts by default, instead opening them in an editor for example.

xdg-open is a Gnome thing I think, but that doesn't mean it's unavailable for other desktops. I know it from Xubuntu (so Xfce).

So I'd really advise against that, But if you want to execute all python files by default in any GUI context, too you could set this kind of default there

'man xdg-open' might help, or maybe you could even select a specific Python executable as the default for .py files after double-clicking in the File Manager.

Again, bad advice

Re: Start all of your commands with a comma (2009)

#64

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…

[deleted]

Re: Start all of your commands with a comma (2009)

#65

I'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?

Symbolic links set up with dotbot[1].

Since the link directives are idempotent, you can run it on every login shell if you desire. I ended up setting up a shared jumpbox used by some contractors with it so they could work with our internal tooling without requiring excessive setup, and wrapped it into a shell startup script[2] and found it performant enough that I couldn't tell the difference.

1: https://github.com/anishathalye/dotbot

2: https://gist.github.com/RulerOf/f41259f493b965c9354c2564d85b...

Re: Start all of your commands with a comma (2009)

#66

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…

> 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/nohtyp`?).

I believe the elegant solution to this is update-alternatives, which lets you tell the system which actual program to call. Maybe look into update-alternatives, I haven't looked into this much but it seems like it might interest you particularly. That's the closest equivalent to file association for the UNIX shell I would guess.

You could also have a specific folder that you control in your PATH that symlinks to the Python you want to use.

This handles the default, but you can still call your script with the program you want if you ever wish to bypass that.

Re: Start all of your commands with a comma (2009)

#68

I'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?

Moin, To manage my dotfiles I use git and an alias. See https://www.atlassian.com/git/tutorials/dotfiles

Re: Start all of your commands with a comma (2009)

#69

> The lower-case letters are the very characters used in system commands; brackets, backslashes, the colon, the back-tick, and the single-tick all had a special meaning to the shell Please note that brackets have no special meaning to the shell.

Brackets have a special meaning in the UNIX shell since the earliest times.

Together with "*" and "?", the brackets "[" and "]" have been used by the UNIX shell since some of its earliest versions (already many years before the Bourne shell) in pattern matching for pathname expansion (globbing).

For example, if you have in a directory 3 files named "file1", "file2" and "file3", then

"ls file?" will output

file1 file2 file3

while "ls file[13]" will output

file1 file3

Post reply on HN