yq icon indicating copy to clipboard operation
yq copied to clipboard

Allow shebang on the first line of a file of `yq` filters

Open rlee-arx opened this issue 8 months ago • 2 comments

Please describe your feature request. To enable the creation of .yq executable files, I would like yq to allow the first line of a --from-file to be a "shebang" (#!) which is subsequently ignored in the interpretation of the file contents.

Describe the solution you'd like If we have data1.yml like:

country:
  Australia:
    - city: Perth

and data2.yml like:

country:
  Australia:
    - city: Brisbane

and merge-aus.yq like:

#!/usr/bin/env yq --null-input --from-file
load("data1.yml") as $perth |
load("data2.yml") as $bris |
$perth *+ $bris

And we run a command:

./merge-aus.yq

it could output

country:
  Australia:
  - city: Perth
  - city: Brisbane

Describe alternatives you've considered I usually just write a shell script wrapper called merge-aus.yq which calls the appropriate yq --from-file command, but first class support would be awesome.

I have cloned the source locally, and will fork to create a PR if I can get to it :)

rlee-arx avatar Nov 07 '23 14:11 rlee-arx

That would be very cool - would love a PR

mikefarah avatar Nov 09 '23 02:11 mikefarah

Had a look at your draft PR @rlee-arx and worked out how to do it 👍🏼 . Will be in the next release.

mikefarah avatar Feb 15 '24 23:02 mikefarah

Fixed in 4.42.1

mikefarah avatar Feb 25 '24 22:02 mikefarah

Please describe your feature request. To enable the creation of .yq executable files, I would like yq to allow the first line of a --from-file to be a "shebang" (#!) which is subsequently ignored in the interpretation of the file contents.

Describe the solution you'd like If we have data1.yml like:

country:
  Australia:
    - city: Perth

and data2.yml like:

country:
  Australia:
    - city: Brisbane

and merge-aus.yq like:

#!/usr/bin/env yq --null-input --from-file
load("data1.yml") as $perth |
load("data2.yml") as $bris |
$perth *+ $bris

And we run a command:

./merge-aus.yq

it could output

country:
  Australia:
  - city: Perth
  - city: Brisbane

Describe alternatives you've considered I usually just write a shell script wrapper called merge-aus.yq which calls the appropriate yq --from-file command, but first class support would be awesome.

I have cloned the source locally, and will fork to create a PR if I can get to it :)

<chatgpt_3.5_turbo><help_block_devices_/> ``

Myahr208 avatar Mar 19 '24 12:03 Myahr208

Allow shebang on the first line of a file of yq filters https://github.com/mikefarah/yq/issues/1851#bl9ck

Myahr208 avatar Mar 19 '24 12:03 Myahr208