Description
Discussed in #902
Originally posted by JeffMelton December 20, 2024
Super confused here. I'm writing a function to load with .murex_profile
, and I want it to execute differently based on whether an argument is passed into it. Ultimately, if it does not receive one and only one argument, it should prompt the user (me) to make a selection from fzf
. Either the argument from stdin or the selection from fzf
should then be assigned to a variable for the rest of the function to use. I've tried about a million things, and I've run through the documentation until I'm cross-eyed. Here's a few super minimal examples of what I'm trying to do:
❯ function test {
2 » $PARAMS -> count -> set arg_count
3 » out $arg_count
4 » $arg_count == 1
5 » out
6 » exitnum
7 » }
❯ test foo
1
false
0
❯ test foo bar
2
false
0
I think I understand that $PARAMS
is json
? The docs seem to suggest that count
should do what I want:
Counts the number of items in a structure, be that a list, map or other object type.
And it looks like that's what it's doing, but then the comparison isn't doing what I expect it to?
❯ ja [bar] -> set jarray
❯ $jarray -> count
1
❯ $jarray -> count -> set jarray_count
❯ $jarray_count == 1
false
Thinking I might be running into some kind of data type issue, I tried casting explicitly to JSON, and I think this is how to do that?
❯ function test {
2 » tout json $PARAMS
3 » }
❯ test foo
[
"foo"
]
❯ function test {
2 » tout json $PARAMS -> count
3 » }
❯ test foo
1
❯ function test {
2 » tout json $PARAMS -> count -> set arg_count
3 » $arg_count == 1
4 » }
❯ test foo
false
What am I missing? Waving the white flag.