edit menu file
This commit is contained in:
@@ -1,31 +1,35 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import subprocess
|
|
||||||
import termios
|
|
||||||
import tty
|
|
||||||
import readline
|
|
||||||
import math
|
import math
|
||||||
|
import os
|
||||||
|
import readline
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import termios
|
||||||
|
import time
|
||||||
|
import tty
|
||||||
|
|
||||||
|
|
||||||
readline.parse_and_bind('tab: complete')
|
readline.parse_and_bind('tab: complete')
|
||||||
readline.parse_and_bind('set editing-mode vi')
|
readline.parse_and_bind('set editing-mode vi')
|
||||||
|
|
||||||
MENUFILE='.foldermenu'
|
MENUFILE = '.foldermenu'
|
||||||
DEFAULTFILE = os.path.expanduser(os.path.join('~','.config','foldermenu','default'))
|
DEFAULTFILE = os.path.expanduser(os.path.join('~','.config','foldermenu','default'))
|
||||||
VERSION="0.4"
|
VERSION = "0.5"
|
||||||
|
DEBUG = False
|
||||||
|
|
||||||
def setup_options():
|
def setup_options():
|
||||||
''' Setup the command line options '''
|
''' Setup the command line options '''
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
parser=ArgumentParser(description="Prints folder specific shell commands stored in '"+MENUFILE+
|
parser=ArgumentParser(description="Prints folder specific shell commands stored in '" + MENUFILE +
|
||||||
"' file, and in addition the executables in the current folder. "+
|
"' file, and in addition the executables in the current folder. " +
|
||||||
"Menufile format for each line: 'description:command'. "+
|
"Menufile format for each line: 'description:command'. " +
|
||||||
"If the command ends in '&' it is run in the background. "+
|
"If the command ends in '&' it is run in the background. " +
|
||||||
"If the command ends in '/' it is a folder, and selecting will enter.")
|
"If the command ends in '/' it is a folder, and selecting will enter. " +
|
||||||
parser.add_argument("-1","--one-shot",action='store_true', dest='once',default=False,
|
"Extra keyboard shortcuts: / Edit ")
|
||||||
help="Launch only once, then exit")
|
parser.add_argument("-1","--one-shot",action = 'store_true', dest = 'once', default = False,
|
||||||
|
help = "Launch only once, then exit")
|
||||||
parser.add_argument("-b","--no-banner", action='store_false', dest='banner', default=True,
|
parser.add_argument("-b","--no-banner", action='store_false', dest='banner', default=True,
|
||||||
help="Do not show banners. Banners are ## starting lines in the file")
|
help="Do not show banners. Banners are ## starting lines in the file")
|
||||||
parser.add_argument("-d","--no-defaults",action='store_false', dest='defaults',default=True,
|
parser.add_argument("-d","--no-defaults",action='store_false', dest='defaults',default=True,
|
||||||
@@ -143,6 +147,7 @@ class entry_collection:
|
|||||||
self.entries = []
|
self.entries = []
|
||||||
self.dirs = []
|
self.dirs = []
|
||||||
self.banner = []
|
self.banner = []
|
||||||
|
self.selected = -1
|
||||||
if self.options.defaults:
|
if self.options.defaults:
|
||||||
self.read_menu(DEFAULTFILE)
|
self.read_menu(DEFAULTFILE)
|
||||||
self.read_menu()
|
self.read_menu()
|
||||||
@@ -397,7 +402,7 @@ class entry_collection:
|
|||||||
for row in formatted:
|
for row in formatted:
|
||||||
print '|'.join(row)
|
print '|'.join(row)
|
||||||
|
|
||||||
def launch(self,key):
|
def launch(self, key):
|
||||||
''' launch the given entry '''
|
''' launch the given entry '''
|
||||||
|
|
||||||
bg = False
|
bg = False
|
||||||
@@ -476,6 +481,21 @@ class entry_collection:
|
|||||||
return
|
return
|
||||||
self.selected = new_value
|
self.selected = new_value
|
||||||
|
|
||||||
|
def edit_menu(self):
|
||||||
|
subprocess.call(
|
||||||
|
"vim %s"%( MENUFILE, ),
|
||||||
|
stderr = subprocess.STDOUT,
|
||||||
|
shell = True,
|
||||||
|
executable = "/bin/bash"
|
||||||
|
)
|
||||||
|
self.initialize()
|
||||||
|
|
||||||
|
def debug_code_print(c):
|
||||||
|
print("- code: %d, str: %s -"%(
|
||||||
|
c,
|
||||||
|
str(c)
|
||||||
|
))
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
def start_engines():
|
def start_engines():
|
||||||
@@ -498,11 +518,16 @@ def start_engines():
|
|||||||
while True:
|
while True:
|
||||||
entries.menu()
|
entries.menu()
|
||||||
inkey = ord(ch.get())
|
inkey = ord(ch.get())
|
||||||
#print('-'+str((inkey))+'-')
|
if DEBUG:
|
||||||
|
debug_code_print(inkey)
|
||||||
if inkey == 27:
|
if inkey == 27:
|
||||||
inkey2 = ord(ch.get())
|
inkey2 = ord(ch.get())
|
||||||
|
if DEBUG:
|
||||||
|
debug_code_print(inkey2)
|
||||||
if inkey2 == 91:
|
if inkey2 == 91:
|
||||||
inkey3 = ord(ch.get())
|
inkey3 = ord(ch.get())
|
||||||
|
if DEBUG:
|
||||||
|
debug_code_print(inkey3)
|
||||||
if inkey3 == 66:
|
if inkey3 == 66:
|
||||||
entries.select_move(1)
|
entries.select_move(1)
|
||||||
if inkey3 == 65:
|
if inkey3 == 65:
|
||||||
@@ -532,7 +557,9 @@ def start_engines():
|
|||||||
readline.set_startup_hook(None)
|
readline.set_startup_hook(None)
|
||||||
if inkey == 46: # .
|
if inkey == 46: # .
|
||||||
entries.flip_mode()
|
entries.flip_mode()
|
||||||
if inkey == 13:
|
if inkey == 47: # /
|
||||||
|
entries.edit_menu()
|
||||||
|
if inkey == 13: # enter
|
||||||
inkey = ord(entries.menu_keys[entries.selected])
|
inkey = ord(entries.menu_keys[entries.selected])
|
||||||
found, message = entries.is_key(chr(inkey))
|
found, message = entries.is_key(chr(inkey))
|
||||||
if found:
|
if found:
|
||||||
|
|||||||
Reference in New Issue
Block a user