Created
January 17, 2018 22:56
-
-
Save scdekov/6f1fc9571116fd4b229af5579ca8b101 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
def get_commands(): | |
commands = [] | |
with open('/home/svetlio/.zsh_history') as zsh_history: | |
for cmd in zsh_history.read().split('\n'): | |
commands.append(cmd[15:]) | |
return commands | |
def get_best_next(crr): | |
commands = get_commands() | |
all_nexts = {} | |
best = ('', 0) | |
for ix, cmd in enumerate(commands): | |
if cmd == crr: | |
next_cmd = commands[ix + 1] | |
if next_cmd not in all_nexts: | |
all_nexts[next_cmd] = 0 | |
all_nexts[next_cmd] += 1 | |
if all_nexts[next_cmd] > best[1]: | |
best = (next_cmd, all_nexts[next_cmd]) | |
return best[0] | |
if __name__ == "__main__": | |
next_cmd = get_best_next(" ".join(sys.argv[1:])) | |
print (' && ' + next_cmd) if next_cmd else '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment