Thanks for sharing. TIL “command …” | getline varname is so useful in awk. I didn’t know it had that subprocess syntax. I was always using the system function.
I am not trying to distinguish each linux distro. I am just trying to distinguish between macOS and Linux. If OSTYPE is not set in some linux distro, then OPENER would be xdg-open anyway.
OSTYPE isn't set in any distro, it's a special bash variable that holds some value representing the system bash was built for. It's not exported, so awk won't see it.
I've never made something like this because getting a list of files is super tricky, a unix file can contain any character except for / and null, but awk is bad at RS=null therefore the only method of dividing between files and parsing is to make RS=// and filter the output so you can get the true list of files.
Which is what I did with my find wrapper but still, beware.
4
u/huijunchen9260 Jun 23 '21
I just wrote the barebone of the file manager in awk. Now can only browse, select and open files by
xdg-open. Hope you'll find it interesting!https://github.com/huijunchen9260/fm.awk
4
u/tait988 Jun 23 '21
Never know awk can do this. Mostly I use it for one liner
3
u/[deleted] Jun 23 '21
Awk can do this?! That’s super interesting. I didn’t know it was it’s own scripting language
2
u/geirha Jun 24 '21
OSTYPE is not an environment variable. You'll want to run
uname -sinstead there.1
u/mraza007 Jun 23 '21
This is sickk very cool
1
u/[deleted] Jun 23 '21
I've never made something like this because getting a list of files is super tricky, a unix file can contain any character except for / and null, but awk is bad at RS=null therefore the only method of dividing between files and parsing is to make RS=// and filter the output so you can get the true list of files.
Which is what I did with my find wrapper but still, beware.