Skip to content

Commit

Permalink
Edited comments + further simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
N-Holzschuch committed Jan 11, 2018
1 parent 22fef48 commit e8a0e64
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions Sessions/MCPSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,11 @@ - (void)ssh_save_id:(int)argc argv:(char **)argv {
}
}

// This is a superset of all commands available. We check at runtime whether they are actually available (using ios_executable)
// todo: extract from commandsAsString()
// List of all commands available, sorted alphabetically:
// Extracted at runtime from ios_system() plus blinkshell commands:
NSArray* commandList;
// Commands that don't take a file as argument:
// Commands that don't take a file as argument (uname, ssh, mosh...):
NSArray* commandsNoFile;
// must end with NULL pointer

void initializeCommandListForCompletion() {
// set up the list of commands for auto-complete:
Expand All @@ -101,21 +100,16 @@ void initializeCommandListForCompletion() {
// add commands from Blinkshell:
[combinedCommands addObjectsFromArray:@[@"help",@"mosh",@"ssh",@"exit",@"ssh-copy-id",@"ssh-save-id",@"config"]];
commandList = [combinedCommands sortedArrayUsingSelector:@selector(compare:)];
// [combinedCommands copy];
commandsNoFile = @[@"help", @"mosh", @"ssh", @"exit", @"ssh-copy-id", @"ssh-save-id", @"config", @"setenv", @"unsetenv", @"printenv", @"pwd", @"uname", @"date", @"env", @"id", @"groups", @"whoami", @"uptime", @"w"];
}

void completion(const char *command, linenoiseCompletions *lc) {
// autocomplete command for lineNoise
// Number of spaces:
size_t numSpaces = 0;
BOOL isDir;
// the number of arguments is *at most* the number of spaces plus one
NSString* commandString = [NSString stringWithUTF8String:command];
char* str = command;
while(*str) if (*str++ == ' ') ++numSpaces; // count spaces
int numCharsTyped = strlen(command);
if (numSpaces == 0) {
if ([commandString rangeOfString:@" "].location == NSNotFound) {
// No spaces. The user is typing a command
// check for pre-defined commands:
for (NSString* existingCommand in commandList) {
Expand Down

0 comments on commit e8a0e64

Please sign in to comment.