I have several cron jobs run every few hours and they generate reports in either plain-text or HTML. When the clock passes some oclock, I use tabopen command with bookmark keywords to open the directories of reports. From there, I open the newly generated reports into new tabs and read them.
The entire procedure doesnt take long, but I think I can save a few keystrokes or mouse clicks, and thats always a good thing, dont you think?
Since the reports are not always generated, because there is a possibility of no new incoming data, and timestamps are attached to report filenames, therefore creating individual bookmark for each report is impossible. So, the best way is to open files under those directories. I always remove those reports once I have read, there is no needs for me to keep them in track since the data is gathered from API of external web services.
To achieve this, there are only two important tasks:
- Listing files on local filesystem and
- Opening the listed files in new tabs in the background
Thats all this code has to do in order to save me a small amount of time. Here is the finished code:
js <<EOF group.commands.add( ['openfiles'], 'Open files into new tabs', function(paths) { paths.forEach(function (path) { for (f in File(File.expandPath(path)).iterDirectory()) { if (f.isFile()) { var params = { background: true, where: dactyl.NEW_TAB }; dactyl.open(f.path, params); } } }); }, { argCount: '*', completer: function (context) { completion.directory(context, true); } } ); EOF
To map the command, just append all the directories I need after the command
map <Leader>o :openfiles ~/path/to/foo ~/path/to/bar<CR>
This openfiles command accepts a number of paths. It uses File.expandFile() to expand ~ into users home directory, then initializes a File with the expanded path. It then walks through all the files in that directory via iterDirectory() and open whatever is a file into background tab.
I think its possible to check with history to see if any of those files has been visited and skip them, but they will be all new to me since I always remove after open them, so I dont code that part.
Coding in Pentadactyl is always a bit tricky for me since there is no such References documentation, so I would have to either find some examples online or just read the source code. Unfortunately, there is not many examples out there, the best way is to read the source code. Nonetheless, so far, I always got what I intended to achieve.