Commits

Iñigo Serna  committed 734a872

Save persistent history between sessions => ~/.lfm_history.

* lfm/lfm.py (HISTORY_FILE): history file
* lfm/lfm.py (lfm_start): load history at start
* lfm/lfm.py (Lfm.quit_program): save history at end
* lfm/config.py: new option: save_history_at_exit

* lfm/config.py (CONFIG_FILE): clean code
* lfm/config.py (Config.__init__):

  • Participants
  • Parent commits c8b0a51

Comments (0)

Files changed (4)

+Mon May 16 00:27:24 2011  Iñigo Serna  <inigoserna@gmail.com>
+
+	* lfm/lfm.py (HISTORY_FILE): history file
+	* lfm/lfm.py (lfm_start): load history at start
+	* lfm/lfm.py (Lfm.quit_program): save history at end
+	* lfm/config.py: new option: save_history_at_exit
+
+Mon May 16 00:26:13 2011  Iñigo Serna  <inigoserna@gmail.com>
+
+	* lfm/config.py (CONFIG_FILE): clean code
+	* lfm/config.py (Config.__init__):
+
 Sun May 15 23:04:45 2011  Iñigo Serna  <inigoserna@gmail.com>
 
 	* lfm/messages.py: use different types of history (path, file, glob, grep,
 ============================================================================
-Last update:	Time-stamp: <2011-05-15 23:15:59 inigo>
+Last update:	Time-stamp: <2011-05-16 00:33:03 inigo>
 ============================================================================
 
 - F11: PowerCLI
   . Stored commands
   . History
-- history
-  . make persistent between sessions => ~/.lfm_history
-    . config flag to enable/disable
-    . format:
-      [type]
-      entry_1
-      ...
 
 
 General:
 - implemented tar un/compress
 - added new extensions: pyw, vala, glade, ui, docx, xlsx, pptx
 - change PowerCLI key shortcut, now Ctrl-X
-- use different types of history (path, file, glob, grep, exec, cli)
-  for the different forms and actions:
-  . path: goto_dir, create_link2, edit_link, copy, move
-  . file: goto_file, touch, create_link1, rename, mkdir
-  . glob: find, select_group, deselect_group
-  . grep
-  . exec: do_something_on_file, execute_file
-  . cli
+- history
+  . use different types of history (path, file, glob, grep, exec, cli)
+    for the different forms and actions:
+    . path: goto_dir, create_link2, edit_link, copy, move
+    . file: goto_file, touch, create_link1, rename, mkdir
+    . glob: find, select_group, deselect_group
+    . grep
+    . exec: do_something_on_file, execute_file
+    . cli
+  . save persistent between sessions => ~/.lfm_history
+    . config flag to enable/disable
 - fixed bugs:
   . pyview:
     . last char is not shown if file size is small

File lfm/config.py

 
 ######################################################################
 ##### Some variables and default values
-CONFIG_FILE = '.lfmrc'
+CONFIG_FILE = '~/.lfmrc'
 defaultprogs = { 'shell': 'bash',
                  'pager': 'pyview',
                  'editor': 'vi',
            'cli_prompt': ('blue', 'black'),
            'cli_text': ('white', 'black') }
 options = { 'save_conf_at_exit': 1,
+            'save_history_at_exit': 1,
             'show_output_after_exec': 1,
             'rebuild_vfs': 0,
             'detach_terminal_at_exec': 1,
     """Config class"""
 
     def __init__(self):
-        self.file = os.path.abspath(os.path.expanduser(os.path.join('~', CONFIG_FILE)))
+        self.file = os.path.abspath(os.path.expanduser(CONFIG_FILE))
         self.file_start = '#' * 10 + ' ' + LFM_NAME + ' ' + \
                           'Configuration File' + ' ' + '#' * 10
         self.progs = {} # make a copy
 # -*- coding: utf-8 -*-
 
 # Copyright (C) 2001-11  Iñigo Serna
-# Time-stamp: <2011-05-15 21:48:59 inigo>
+# Time-stamp: <2011-05-16 00:23:14 inigo>
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 import logging
 import curses
 import curses.panel
+import cPickle as pickle
 
 from __init__ import *
 from config import Config, colors
 ######################################################################
 ##### Global variables
 LOG_FILE = os.path.join(os.getcwd(), 'lfm.log')
+HISTORY_FILE = os.path.abspath(os.path.expanduser('~/.lfm_history'))
 MAX_TAB_HISTORY = 15
 
 
                 vfs.exit(tab)
         if self.prefs.options['save_conf_at_exit']:
             self.prefs.save()
+        if self.prefs.options['save_history_at_exit']:
+            pickle.dump(messages.history, file(HISTORY_FILE, 'w'), -1)
         if icode == -1: # change directory
             return self.act_pane.act_tab.path
         else:           # exit, but don't change directory
         usage('Incorrect number of arguments')
         lfm_exit(-1)
 
+    # history
+    if prefs.options['save_history_at_exit']:
+        try:
+            messages.history = pickle.load(file(HISTORY_FILE, 'r'))
+        except:
+            messages.history = {'path': [], 'file': [], 'glob': [], 'grep': [], 'exec': [], 'cli': []}
+    else:
+        messages.history = {'path': [], 'file': [], 'glob': [], 'grep': [], 'exec': [], 'cli': []}
+
     # logging
     if DEBUG:
         log_file = os.path.join(os.path.abspath(u'.'), LOG_FILE)