Live data from Hacker News

Start all of your commands with a comma (2009)

rhodesmill.org

101–110 of 130 posts

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

#102
post #8

Clever trick. Too bad there's no good way to namespace commands. It would be interesting if you could have, for instance: $ mkdir -p /tmp/bin/my $ printf '%s\n%s\n' '#!/bin/sh' 'echo hello' > /tmp/bin/my/hello $ chmod 755 /tmp/bin/my/hello $ PATH="/tmp/bin:$PATH" $ my/hello hello

I think shells should support that, allowing you to do

  $ my hello
It would mean tools such as git, microk8s and aws wouldn’t have to implement that “look up first argument, check whether it’s a command I know, and if so, run it” on their own, and would have slightly simpler auto complete configs.

It also could mean launching fewer processes (for the case where ‘my’ is a script or executable that looks up the location of ‘hello’ and launches it)

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

#103
post #36

Earlier quoted context omitted.

Just env vars? env > "$(date +s).env-snapshot" (And use it again slightly more awkwardly as or something more convenient to `cmd`.)

Should be

Oops, you've exposed that it started off as a useless cat I knew I'd be chastised for ;)

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

#104
I misadvertantly lower cased my functions names when working on .net, but it made it super easy to find my code in the stack traces. (.net idiom is capitalism the first case of a function name). Usually the cause of stack traces was my code so it was an unexpected productivity booster.

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

#106
Can't you just declare:

    my() {
  script_name="$1"
  script_path="$HOME/.local/bin/my/$script_name"
  shift
  $script_path "$@"
    } 
So you have your namespace ? Of course that mean you must put all script in .local/bin, not anywhere in the PATH, and some more work is needed to figure out completion.

But it seems less weird than the comma.

-- EDIT --

With completion:

export MY_SCRIPS_DIR="$HOME/.local/bin/my"

_my_completions() {

   if [ "${#COMP_WORDS[@]}" != "2" ]; then
     return 
   fi

   COMPREPLY=($(compgen -W "$(echo $(find "$MY_SCRIPS_DIR" -printf '%P\n' ))"))
 }


 my() {
  script_name="$1"
  script_path="$MY_SCRIPS_DIR/$script_name"
  shift
  $script_path "$@"
 } 

 complete -F _my_completions my
-- EDIT 2 --

After testing both, the comma win. Kiss, more flexible.

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

#107
post #8

Clever trick. Too bad there's no good way to namespace commands. It would be interesting if you could have, for instance: $ mkdir -p /tmp/bin/my $ printf '%s\n%s\n' '#!/bin/sh' 'echo hello' > /tmp/bin/my/hello $ chmod 755 /tmp/bin/my/hello $ PATH="/tmp/bin:$PATH" $ my/hello hello

https://ianthehenry.com/posts/sd-my-script-directory/

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

#110
I have my bin folder in ~/usr/bin. The structure of ~/usr matches /usr and /usr/local, so I can build stuff into it with ./configure --prefix=$HOME/usr or similar. (You could of course do ./configure --prefix=$HOME, but then you run the risk of ending up with ~/share and ~/include and so on, something I don't want.)
Post reply on HN