Jump to content

Workflow to search Terminal history

Recommended Posts

Hi guys 'n girls,


As I never can exactly remember all the different commands I'm using in the Terminal, and since I could not find an existing workflow for this, I wrote something small: http://www.packal.org/workflow/search-terminal-history


Hopefully it is helpful for others too. Might be useful to set the option HISTFILESIZE=10000000 in your .bash_profile if you want to retain history longer than the default 500 lines.



Link to comment
  • 1 month later...

Hey, couldn't find a github link but i made some changes to the file for ZSH. if someone wants to be able to use this with ZSH just replace the file term_hist.py with this:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import unicodedata
import codecs
from os.path import expanduser
from workflow import Workflow, ICON_WEB, web, ICON_WARNING

def main(wf):
    """Execute the query on bash_history and return results

    args = wf.args
    query = " ".join(args)
    home = expanduser("~")

    results = []
    with codecs.open(home+"/.zsh_history", "r", encoding='ISO-8859-2') as f:
      searchlines = reversed(f.readlines())
      for i, line in enumerate(searchlines):
        if query in line: 
 	  histstart = line.encode("utf-8","ignore").partition(":0;")

    for i in range(len(results)):
                arg = results[i],
    return 0

if __name__ == u"__main__":
    wf = Workflow()

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...