#!/usr/bin/python import os import random from sys import argv mypath = argv[0] def ext_resolver(filename): ext = filename.split('.')[-1] ext = ext.lower() ext_list = {'nes':'tuxnes -E --js1=/dev/input/js0 --joystick-map=1:B2,B1,B9,B8,,,,,B3', 'smc':'zsnes -m -v 18 -y', 'gba':'VisualBoyAdvance', 'bin':'dgen -f -j', 'ape':'xdg-open ', 'flac':'xdg-open ', 'ogg':'xdg-open ', 'ogm':'xdg-open ', 'mp3':'xdg-open ', 'avi':'xdg-open ', 'divx':'xdg-open ', 'm4a':'xdg-open ', 'm4v':'xdg-open ', 'mkv':'xdg-open ', 'mp4':'xdg-open ', 'vob':'xdg-open ', 'py' : 'xdg-open ', 'png':'xdg-open ', 'jpg':'xdg-open ', 'bmp':'xdg-open ', 'gif':'xdg-open ', 'svg':'xdg-open ', 'tex':'xdg-open ', 'txt':'xdg-open ', 'xml':'xdg-open ', 'pdf':'xournal', 'ps':'xournal', 'html':'x-www-browser', 'html5':'x-www-browser', 'deb':'gdebi', 'desktop':'gksudo geany', 'sh':'xdg-open geany', 'exe':'wine start /unix', 'jar':'java -jar'} if ext in ext_list: return ext_list[ext] else: return 'echo' def dir_list(dircontent): dirs = [] files = [] for item in dircontent: if os.path.isdir(currentpath + '/' + item): dirs.append(item) else: files.append(item) dirs.sort() files.sort() return dirs, files def replacer(string): return string.replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"').replace("'", ''') def gen_menu(dirs, files): curpath = replacer(currentpath) print('') print('lxterminal --working-directory="' + curpath + '"') print('thunar "' + curpath + '"') print('') for thisdir in dirs: thisdir = replacer(thisdir) menuid = str(random.randrange(1,99,1)).zfill(2) print(' ') for thisfile in files: thisfile = replacer(thisfile) print(' ') print(' ') print(' ') print(' ' + ext_resolver(thisfile) + ' "' + curpath + '/' + thisfile + '"') print(' ') print(' ') print(' ') print('') if len(argv) > 1: currentpath = ' '.join(argv[1:]) else: currentpath = "/home/chris/.config" try: content = [x for x in os.listdir(currentpath) if x[0] != '.'] parts = dir_list(content) gen_menu(parts[0], parts[1]) except OSError: print('') print('') print('')