Code Sample |
#!/bin/lua -- Launches applications under X -- by Daniel Plata Lorenzo "MakodFilu" version="1.0.0" max_history=10 history_file=os.getenv("HOME").."/.flrun_history" gassoc_file="/opt/grun/gassoc" ww=250 --window width wh=100 --window height bw=60 --button width bh=25 --button height -- L10N (Somewhat) window_text="flRun v"..version -- Try FireSomething for the fun of it input_text="Launch Application" cancel_text="&Cancel" cancel_tooltip="Cancel launch" ok_text="&Ok" ok_tooltip="Launch application" browse_text="&Browse" browse_tooltip="Browse for command" choose_text="Choose Application" -- Code w=fltk:Fl_Window(ww,wh,window_text) history_table={} table_length=0 file = io.open(history_file, "r") if file then for line in file:lines() do table.insert(history_table, line) end file:close() table_length=table.maxn(history_table) if not table_length then table_length=0 end end gassoc_table={} file = io.open(gassoc_file, "r") if file then for line in file:lines() do table.insert(gassoc_table,{ line:sub(line:find(".*%f[:]")); line:sub(line:find("%a*$"))}) end file:close() end input = fltk:Fl_Input_Choice(10,30,ww-20,bh,input_text) input:align(fltk.FL_ALIGN_TOP) if table_length~=0 then input:value(history_table[table_length]) -- Show last feed command for i=1,table_length,1 do input:add(history_table[i]) end end ok = fltk:Fl_Return_Button(ww-3*bw*1.2,wh-35,bw,bh,ok_text) ok:tooltip(ok_tooltip) ok:callback( function(ok) if input:value() == "" then io.write(string.char(7)) io.flush() else if table_length < max_history then start=1 else start=table_length-(max_history-2) -- Discard older entries end io.output(io.open(history_file,"w+")) for i=start,table_length,1 do if history_table[i]~=input:value() then io.write(history_table[i]..'\n') end end io.write(input:value()..'\n') io.close() command=input:value() if command:find("%.%a*$") then ext=command:sub(command:find("%.%a*$")) for i=1,table.maxn(gassoc_table),1 do if ext == '.'..gassoc_table[i][1] then command=gassoc_table[i][2]..' '..command end end end os.execute(command..' 2>/dev/null &') os.exit(0) end end) cancel = fltk:Fl_Button(ww-2*bw*1.2,wh-35,bw,bh,cancel_text) cancel:tooltip(cancel_tooltip) cancel:callback( function(cancel) os.exit(0) end) browse = fltk:Fl_Button(ww-1*bw*1.2,wh-35,bw,bh,browse_text) browse:tooltip(browse_tooltip) browse:callback( function(browse) input:value(fltk.fl_file_chooser(choose_text,"*",single,nil)) end) if not arg[1] then w:show() Fl:run() else print ("flRun v"..version.." launches applications under X\n") print "Usage flrun\n" -- [options] [file options]\n" -- print " file options Launch file directly, no dialog boxes" -- print " --persist Dialog persistance" -- print " --preload file Load file as default command" -- print " --notips Disable tooltips" -- print " --version Show version" -- print " --help Show this guide\n" end |
Code Sample |
#!/bin/lua -- Launches applications under X -- by Daniel Plata Lorenzo "MakodFilu" version="1.0.0" max_history=10 history_file=os.getenv("HOME").."/.flrun_history" gassoc_file="/opt/grun/gassoc" ww=250 --window width wh=100 --window height bw=60 --button width bh=25 --button height -- L10N (Somewhat) window_text="flRun v"..version -- Try FireSomething for the fun of it input_text="Launch Application" cancel_text="&Cancel" cancel_tooltip="Cancel launch" ok_text="&Ok" ok_tooltip="Launch application" browse_text="&Browse" browse_tooltip="Browse for command" choose_text="Choose Application" -- Code w=fltk:Fl_Window(ww,wh,window_text) history_table={} table_length=0 file = io.open(history_file, "r") if file then for line in file:lines() do table.insert(history_table, line) end file:close() table_length=table.maxn(history_table) if not table_length then table_length=0 end end assoc = {} file = io.open(gassoc_file, "r") if file then for line in file:lines() do i,_ = string.find(line,":") if i then local j = #assoc+1 assoc[j] = {} assoc[j][1] = string.sub(line,1,i-1) assoc[j][2] = string.sub(line,i+1) end end end input = fltk:Fl_Input_Choice(10,30,ww-20,bh,input_text) input:align(fltk.FL_ALIGN_TOP) if table_length~=0 then input:value(history_table[table_length]) -- Show last feed command for i=1,table_length,1 do input:add(history_table[i]) end end ok = fltk:Fl_Return_Button(ww-3*bw*1.2,wh-35,bw,bh,ok_text) ok:tooltip(ok_tooltip) ok:callback( function(ok) if input:value() == "" then io.write(string.char(7)) io.flush() else if table_length < max_history then start=1 else start=table_length-(max_history-2) -- Discard older entries end io.output(io.open(history_file,"w+")) for i=start,table_length,1 do if history_table[i]~=input:value() then io.write(history_table[i]..'\n') end end io.write(input:value()..'\n') io.close() command=input:value() if command:find("%.%a*$") then ext=command:sub(command:find("%.%a*$")) for i=1,#assoc,1 do if ext == '.'..assoc[i][1] then command=assoc[i][2]..' '..command end end end os.execute(command..' 2>/dev/null &') os.exit(0) end end) cancel = fltk:Fl_Button(ww-2*bw*1.2,wh-35,bw,bh,cancel_text) cancel:tooltip(cancel_tooltip) cancel:callback( function(cancel) os.exit(0) end) browse = fltk:Fl_Button(ww-1*bw*1.2,wh-35,bw,bh,browse_text) browse:tooltip(browse_tooltip) browse:callback( function(browse) input:value(fltk.fl_file_chooser(choose_text,"*",single,nil)) end) if not arg[1] then w:show() Fl:run() else print ("flRun v"..version.." launches applications under X\n") print "Usage flrun\n" -- [options] [file options]\n" -- print " file options Launch file directly, no dialog boxes" -- print " --persist Dialog persistance" -- print " --preload file Load file as default command" -- print " --notips Disable tooltips" -- print " --version Show version" -- print " --help Show this guide\n" end |