fogine / rofi-search

Interactive Google / DuckDuckGo search via rofi
MIT License
100 stars 7 forks source link

DX Suggestions and ... questions. #11

Open airtonix opened 6 months ago

airtonix commented 6 months ago

One

number one on my wtf list is this:

#!/bin/sh
':' //; exec "$(command -v nodejs || command -v node)" "$0" "$@"

console.log('Hello world');

I understand this part: $(command -v nodejs || command -v node)" "$0" "$@"

but the part I'm not entirely understanding is ':' //; :

Second

this lead me to be think about the experience editing this file:

There's no automatic correct syntax highlighting (whole file is considered bash so shellcheck screams about everything)

So the second question is did you try this instead:

image


My only assumption is that you're trying to account for ubuntu users that incorrectly have nodejs installed via apt as nodejs.

Ganjalek commented 6 months ago

One

number one on my wtf list is this:

#!/bin/sh
':' //; exec "$(command -v nodejs || command -v node)" "$0" "$@"

console.log('Hello world');

I understand this part: $(command -v nodejs || command -v node)" "$0" "$@"

  • if there's a command on called nodejs, or node, then
  • execute the current file "$0" with whatever args were passed originally "$@"

but the part I'm not entirely understanding is ':' //; :

  • ':' i get that this is just a string so bash does nothing with it?
  • // ; ???? lmao wut?

Second

this lead me to be think about the experience editing this file:

  • because it ends in .sh, or
  • because there's no vim modelines,

There's no automatic correct syntax highlighting (whole file is considered bash so shellcheck screams about everything)

So the second question is did you try this instead:

  • rename the file to rofi-search.js (now the file gets automatic syntax highlighting regardless of the editor)
  • change the hashbang to #!/usr/bin/env node (now the js file will execute with nodejs)

image

My only assumption is that you're trying to account for ubuntu users that incorrectly have nodejs installed via apt as nodejs.

fogine commented 6 months ago

but the part I'm not entirely understanding is ':' //; : ':' i get that this is just a string so bash does nothing with it? // ; ???? lmao wut?

Its the part that makes it syntactically valid both in shell and javascript at the same time. Explanation here: https://unix.stackexchange.com/questions/65235/universal-node-js-shebang

My only assumption is that you're trying to account for ubuntu users that incorrectly have nodejs installed via apt as nodejs.

yes #!/usr/bin/env node would fail if users have installed nodejs via apt.

Since this project is not updated often, compatibility has had bigger priority. if needed, I set the syntax highlighting manually in vim.

At the time of creating this I wanted just single file that could be executed everywhere.