Add bash completion
mjpitz opened this issue · 3 comments
Thought about this a little bit, but I typically use this to tail the same files every couple of days. We should be able to add bash completion support by creating a history file and using it to auto-complete values that you've entered in the past.
Technical Details
- For each value in program.args:
- Check the history file for the value
- If the value does not exist, append the entry and set the count to 1.
- If the value does exist, then increment the count.
- Write the history back ordered by access count.
Example
The history file currently contains:
4 trillworks.com:/var/log/nginx/access.log
2 okpedro.com:/var/log/apache2/other_vhosts_access.log
After executing the remtail trillworks.com:/var/log/nginx/access.log
, the new history file would be:
5 trillworks.com:/var/log/nginx/access.log
2 okpedro.com:/var/log/apache2/other_vhosts_access.log
Not sure if the count is necessary as these will be auto complete values and as far as bash is concerned for the auto-complete, it would just use second part of the line anyway.
Great idea. I often find myself sshing into the remote hosts just to get the paths right which is a huge pain.
Worked this up really quick. One big bug with the way it handles the completion post : . Looked into it a little but didn't spend too much time on it. I also had another iteration where I was using -F instead of -C for the results but I think this one is a little cleaner (although not by much). I think the completion is trying to treat the : as a word separator
_remtail_complete() {
local word=${COMP_WORDS[COMP_CWORD]}
local completions="$(cat ~/.remtail_history | awk '{print $2}' | grep ^$word)"
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
}
complete -F _remtail_complete remtail
There is value is rolling this into the javascript code. Then we can autocomplete command flags: 760c935
Not done, but you can see where it was going.