New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
~/Documents/bin
: #!sh
, #!bc
, ... -> not executable
#198
Comments
~/Documents/bin
: #!sh
, #!bc
not respected~/Documents/bin
: #!sh
, #!bc
, ... -> not executable
Yes, that is currently the case. The offending lines are in I try to read the first line, infer if it is a scripting language and if so add it to the beginning of the command line. I think I could just take the last word of the first line, if it begins with "#!". It's not going to work with "#!sh", for the time being, but it will work with other shells. |
I have almost no experience with ObjectiveC, so this is probably partially wrong, but maybe, ... lua case ... (line 2311)
} else {
// Leave scriptName untouched.
// Ref: https://stackoverflow.com/questions/11325951/how-to-split-a-string-of-words-and-add-to-an-array-objective-c
NSArray* newArgs = [firstLine componentsSeparatedByString: @" "];
int numNewArgs = [newArgs count]; // Or is it .length???
argc += numNewArgs + 1;
argv = (char**) realloc(argv, sizeof(char*) * (argc));
// Shift existing arguments
for (int i = numNewArgs; i <= argc; i++) {
argv[i] = argv[i - numNewArgs];
}
int i = 0;
for (NSString* newArg in newArgs) {
argv[i] = strdup(newArg.UTF8String);
i++;
}
argv[i] = realloc(argv[i], locationName.length + 1);
strcpy(argv[i], locationName.UTF8String);
break;
}
if (scriptName) {
// 2) insert script language at beginning of argument list
argc += 1;
argv = (char **)realloc(argv, sizeof(char*) * (argc + 1));
// Move everything one step up
for (int i = argc; i >= 1; i--) { argv[i] = argv[i-1]; }
argv[1] = realloc(argv[1], locationName.length + 1);
strcpy(argv[1], locationName.UTF8String);
argv[0] = strdup(scriptName); // this one is new
break;
} By adding the additional handling in an |
I've opted for something more extreme: NSCharacterSet *invertedAlphaNumCharSet = [[NSCharacterSet alphanumericCharacterSet] invertedSet];
NSArray *components = [firstLine componentsSeparatedByCharactersInSet:invertedAlphaNumCharSet];
NSString *scriptNameString = components.lastObject; The name of the script is the last word of the line, word being defined as "a set of alphanumeric characters". This works with The only thing it does is add the name of the command in front of the file, so it does not work so well with I'm uploading the new version now; it should be available for TestFlight in 24 to 36h. |
The new build has been submitted for TestFlight, but I just realized: it's not going to be enough for |
Although NSCharacterSet *invertedAlphaNumCharSet = [[NSCharacterSet alphanumericCharacterSet] invertedSet];
NSArray *components = [firstLine componentsSeparatedByCharactersInSet:invertedAlphaNumCharSet];
NSString *scriptNameString = components.lastObject; works for commands like |
Ah, yes. It's going to be difficult to have a regex that matches both |
It looks like build 155 broke ipython. See #204. |
Build 157 has improved on the shebang analysis: all arguments are transferred to the beginning of the command line, so "#! bc -f" works now. "#!almake_shell" wont't work, because we don't loop back to the beginning to parse the new command if it's a file, but I think "#!python almake_shell" might work. "#!sh" of course still won't work. I'm also not fully satisfied with the treatment of "python": to make it work with "python3.9", everything that contains the string "python" is remapped to "python", but that seems like too much, and something that will create issues later. |
|
That's great! |
I have a python script which I have set to executable using chmod. The first line of the script says #!python. However when I try to run it by typing the file name I am getting command not found. Should this work? |
Is the python script in |
Sorry, my bad, |
My .py file is in the documents/bin directory and it is set to executable. It has |
I stand corrected. It does work (there was a spurious blank line at the beginning of the file). However command completion does not work for this file. Should it? |
I think the list for commant completion is computed only once, at the start of the program. It should appear on the next run. |
I had restarted it and still had the problem but I think I understand why. If I type the first few letters of the command and then hit tab for command completion I am getting a different command and I am not being shown any alternatives. If I type enough characters so that the command name is unambiguous and then hit tab, I get the command I’m looking for. Specifically, my command is wordleai.py and if I type word+tab, I get wordcloud.cli. |
Tab shows the first match, but you can use the arrows to scroll through the other possible matches (or, as you did, type more letters) |
OK, it works except for one thing. If I type part of the command and then hit tab, the full name is filled in, but when I hit return I always get "command not found" BUT only the first time after starting ashell. Every subsequent attempt works fine. |
Summary
#!command_name
at the top of an executable text file seems to only work ifcommand_name
ispython
orlua
.Expected Behavior
~/Documents/bin/test1
:or
or
~/Documents/bin/test2
:test1
andtest2
should produce the same output.Thank you for your time!
The text was updated successfully, but these errors were encountered: