Module: Naksh
- Defined in:
- lib/old/systems.rb,
lib/naksh.rb,
lib/naksh.rb,
lib/naksh/buffer.rb,
lib/naksh/syntax.rb,
lib/old/commands.rb,
lib/naksh/history.rb,
lib/naksh/session.rb,
lib/old/abbr_call.rb,
lib/naksh/interfaces.rb,
lib/old/old_executor.rb,
lib/old/systems/ruby.rb,
lib/naksh/syntax/bash.rb,
lib/rust/parsers/bash.rb,
lib/naksh/commands/bsd.rb,
lib/naksh/commands/dos.rb,
lib/naksh/commands/gnu.rb,
lib/naksh/commands/fuse.rb,
lib/naksh/commands/ruby.rb,
lib/naksh/commands/unix.rb,
lib/naksh/interfaces/fox.rb,
lib/naksh/interfaces/gtk.rb,
lib/naksh/interfaces/tab.rb,
lib/naksh/interfaces/wxw.rb,
lib/naksh/command_handling.rb,
lib/naksh/interfaces/gtk/io.rb,
lib/naksh/interfaces/wxw/io.rb,
lib/naksh/configuration/hash.rb,
lib/naksh/configuration/gconf.rb,
lib/naksh/interfaces/gtk/abtwin.rb,
lib/naksh/interfaces/gtk/optwin.rb,
lib/naksh/interfaces/wxw/abtwin.rb,
lib/naksh/interfaces/wxw/optwin.rb,
lib/naksh/interfaces/gtk/helpwin.rb,
lib/naksh/interfaces/gtk/mainwin.rb,
lib/naksh/interfaces/wxw/helpwin.rb,
lib/naksh/interfaces/wxw/mainwin.rb,
lib/naksh/interfaces/gtk/gnomeapp.rb,
lib/naksh/interfaces/gtk/mainwin/console.rb,
lib/naksh/interfaces/wxw/mainwin/sessions.rb,
lib/naksh/interfaces/gtk/mainwin/main_menu.rb,
lib/naksh/interfaces/wxw/mainwin/main_menu.rb
Overview
This file is part of Naksh.
Naksh is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Naksh is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Naksh. If not, see <www.gnu.org/licenses/>.
Defined Under Namespace
Modules: CommandSets, Commands, Interfaces, NonCriticalError, Syntax, Systems Classes: BufferClass, GConfStyleHash, History, Session
Constant Summary collapse
- USAGE_STRING =
'naksh.rb [-h | --help][-a | --about][(-e | --execute) script_str]* [(-f | --file) script_path]'
- OPTION_LIST =
['-? | -h | --help','-a | --about','-c | --copyright','-u | --usage',['-e | --execute','shell_script_string'],['-f | --file','path_to_shell_script']]
- UNIX_SHELL_LOCATIONS =
includes only compatible shell locations
%w[/usr/bin/bash /usr/bin/sh]
Class Method Summary collapse
- .abbr_call(abbr, ary_of_args) ⇒ Object
- .attempt_submit(config_entry) ⇒ Object
- .buffer ⇒ Object
-
.config ⇒ Object
config is a gconf2 client it looks like a hash keys look like a UNIX file path.
-
.current_session ⇒ Object
Only one session may be considered ‘active’ or ‘current’ at a given time.
- .current_session=(new_current_session) ⇒ Object
- .evaluate_path(str) ⇒ Object
-
.file_is_shell_script?(file) ⇒ Boolean
includes only compatible shells.
- .interface ⇒ Object
-
.interface=(new_interface) ⇒ Object
set a new syntax ruleset currently no way to combine syntax rulesets except by method overwriting.
- .option_list ⇒ Object
-
.path ⇒ Object
this is just what you expect it to be, an Array of path entries, see PathEntry.
-
.path=(new_path) ⇒ Object
this is in case you want to save and swap paths, very useful.
- .quit ⇒ Object
-
.refresh_history ⇒ Object
call this whenever your going to change the history position or modify Naksh.interface.in.
-
.replace_vars(str) ⇒ Object
replaces %var with var.value.
-
.run_external_file(location, args) ⇒ Object
this is for normal commands you can run from any shell.
-
.run_file_by_shebang(file) ⇒ Object
if user is running a UNIXish operating system, executes via OS if not, will run in Naksh if a shell script.
-
.run_nkc(location, args) ⇒ Object
running a command made for us is easy as pie.
-
.run_scripts(care_about_memory = false) ⇒ Object
fetches scripts and executes them one optional argument (The_scripts_may_be_very_long)? true : false.
- .send_command(command, args) ⇒ Object
-
.sessions ⇒ Object
an Array of all active sessions, in no significant order however, the order must not be changed during runtime, since the interfaces depend upon it.
- .shebang(file) ⇒ Object
-
.suggestions(com_str) ⇒ Object
this should be a spell checker Naksh.suggestions(‘xml-cpy-editor’)#=>‘xml-copy-editor’ autocomplete is the next best thing.
- .syntax ⇒ Object
-
.syntax=(new_syntax) ⇒ Object
set the current syntax ruleset currently no way to combine syntax rulesets except by method overwriting eg., you could define a command ‘ren’ which joins it’s arguments and executes them with the Ren interpreter.
Class Method Details
.abbr_call(abbr, ary_of_args) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/old/abbr_call.rb', line 24 def Naksh.abbr_call(abbr,ary_of_args) possibilities=Naksh.autocomplete(abbr) if possibilities.length==1 Naksh.send_command(possibilities[0],ary_of_args) else Naksh.send_error(_("%{command}: command not found")%{:command=>command}) if Naksh..suggest_on_failure? Naksh.buffer.puts(_('Try one of the following commands:')) Naksh.pretty_print_array(possibilities) end Naksh.stop#cancel any later commands end end |
.attempt_submit(config_entry) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/naksh.rb', line 69 def Naksh.attempt_submit config_entry case Naksh.config[config_entry] when 'submit' input=Naksh.interface.in Naksh.interface.on_pre_submit if Naksh.syntax.complete? input begin return false unless Naksh.syntax.try_execute(input) rescue Naksh::NonCriticalError=>error Naksh.buffer.clear Naksh.interface.err.print((_('Naksh: %s')%[error.to_s])<<"\n") end Naksh.current_session.history.position=Naksh.current_session.history.length Naksh.current_session.history<<input Naksh.interface.new_prompt return true else return false end when 'char' return false else $stderr.puts _("Naksh.config[%s] has unrecognized value: %s")%[config_entry,Naksh.config[config_entry].inspect] return nil end raise RuntimeError,_('this should never be executed') end |
.buffer ⇒ Object
149 150 151 |
# File 'lib/naksh/buffer.rb', line 149 def Naksh.buffer @buffer end |
.config ⇒ Object
config is a gconf2 client it looks like a hash keys look like a UNIX file path
45 46 47 |
# File 'lib/naksh/configuration/gconf.rb', line 45 def Naksh.config @config end |
.current_session ⇒ Object
Only one session may be considered ‘active’ or ‘current’ at a given time. This could be resolved by associating each session with its own buffer.
34 35 36 |
# File 'lib/naksh/session.rb', line 34 def Naksh.current_session @current_session end |
.current_session=(new_current_session) ⇒ Object
37 38 39 |
# File 'lib/naksh/session.rb', line 37 def Naksh.current_session= new_current_session @current_session=new_current_session end |
.evaluate_path(str) ⇒ Object
120 121 122 123 124 125 126 127 |
# File 'lib/naksh.rb', line 120 def Naksh.evaluate_path(str) if path.match(/\A\//) and File.exist? path return path else Naksh.interface.err.puts _('addpath: invalid filepath') return false end end |
.file_is_shell_script?(file) ⇒ Boolean
includes only compatible shells
81 82 83 |
# File 'lib/old/old_executor.rb', line 81 def Naksh.file_is_shell_script?(file) Naksh::UNIX_SHELL_LOCATIONS.include? Naksh.shebang(file) end |
.interface ⇒ Object
55 56 57 |
# File 'lib/naksh/interfaces.rb', line 55 def Naksh.interface @interface end |
.interface=(new_interface) ⇒ Object
set a new syntax ruleset currently no way to combine syntax rulesets except by method overwriting
50 51 52 |
# File 'lib/naksh/interfaces.rb', line 50 def Naksh.interface=(new_interface) @interface=new_interface end |
.option_list ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/old/old_executor.rb', line 36 def Naksh.option_list Naksh::OPTION_LIST.inject do |result,option| if option.kind_of? String result<<' '<< option elsif option.kind_of? Array and option.length==2 result<<' '<< option.at(0)<<' '<< option.at(1) else raise RuntimeError,'internal variable (Naksh::OPTION_LIST) is Array with entries not prepared for' end result end end |
.path ⇒ Object
this is just what you expect it to be, an Array of path entries, see PathEntry
44 45 46 |
# File 'lib/naksh/command_handling.rb', line 44 def Naksh.path @path end |
.path=(new_path) ⇒ Object
this is in case you want to save and swap paths, very useful
50 51 52 |
# File 'lib/naksh/command_handling.rb', line 50 def Naksh.path=(new_path) @path=new_path end |
.quit ⇒ Object
98 99 100 101 |
# File 'lib/naksh.rb', line 98 def Naksh.quit Naksh.interface.quit true end |
.refresh_history ⇒ Object
call this whenever your going to change the history position or modify Naksh.interface.in
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/naksh/history.rb', line 24 def Naksh.refresh_history csh=Naksh.current_session.history puts "NOTICE: refresh_history, position=(#{csh.position})" if csh.position+1==csh.length and csh[csh.position]!=csh.last csh<<Naksh.interface.in csh.position=csh.length-1 end puts "NOTICE: refresh_history, position=(#{csh.position})" true end |
.replace_vars(str) ⇒ Object
replaces %var with var.value
112 113 114 115 116 117 |
# File 'lib/naksh.rb', line 112 def Naksh.replace_vars(str) str=str.gsub('%{pwd}',Naksh.config['/env/pwd'].sub(/\A/+Naksh.config['/env/home'],'~')) str.gsub!('%{user}',Naksh.config['/env/user']) str.gsub!('%{host}',Naksh.config['/env/host']) str end |
.run_external_file(location, args) ⇒ Object
this is for normal commands you can run from any shell
70 71 72 73 |
# File 'lib/naksh/command_handling.rb', line 70 def Naksh.run_external_file(location,args) $stderr.puts 'external command execution not yet implemented' 0 end |
.run_file_by_shebang(file) ⇒ Object
if user is running a UNIXish operating system, executes via OS if not, will run in Naksh if a shell script
86 87 88 89 90 |
# File 'lib/old/old_executor.rb', line 86 def Naksh.run_file_by_shebang(file) return system(Naksh.shebang(file)<<' '<<file.path) if $OS.unix? return Naksh.process_script_progressively(file) if Naksh.file_is_shell_script(file) return false end |
.run_nkc(location, args) ⇒ Object
running a command made for us is easy as pie
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/naksh/command_handling.rb', line 57 def Naksh.run_nkc(location,args) begin prc=eval(File.new(location.to_s).read) rescue Exception=>err raise NkcLoadError,_('error in command: %s: `%s\'')%[location.sub(File.join(Naksh.config['/dir'],'lib'),''),err.to_s.sub(/\(eval\):\d+:in\s`run_nkc':\scompile error\s*/,"\n")] end raise NotExpectedFiletypeError,_("#{location} isn't a compatible NKC") unless prc.kind_of? Proc or not prc.lambda? raise CompatibilityError,_(location.to_s+' must be written for a future version of Naksh; it requires too many arguments') unless prc.arity.abs==1 prc.call(args) end |
.run_scripts(care_about_memory = false) ⇒ Object
fetches scripts and executes them one optional argument (The_scripts_may_be_very_long)? true : false
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/old/old_executor.rb', line 51 def Naksh.run_scripts(care_about_memory=false) Naksh.fetch_scripts.at(0).each do |shell_script| Naksh.process_script_string(shell_script) end Naksh.fetch_scripts.at(1).each do |shell_script_path| if care_about_memory Naksh.process_script_progressively(File.new(shell_script_path)) else Naksh.process_script_string(File.read(shell_script_path)) end end end |
.send_command(command, args) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/naksh/command_handling.rb', line 76 def Naksh.send_command(command,args) raise ArgumentError unless command.kind_of? String and args.kind_of? Array @path.each do |path_entry| case path_entry.type when :nkc return run_nkc(path_entry.location,args) if path_entry.name==command when :external return run_external_file(path_entry.location,args) if path_entry.name==command when :nkc_dir path_entry.location.children.each do |child| begin return run_nkc(child,args) if (/\A(.+)\.nkc\.rb\z/.match(File.basename(child))[1])==command rescue Naksh::NonCriticalError=>error Naksh.buffer.clear Naksh.interface.err.print((_('Naksh: %s')%[error.to_s])<<"\n") return false rescue NoMethodError end end when :external_dir path_entry.location.children.each do |child| return run_external_file(path_entry.location,args) if File.basename(child)==command and File.file? child end when :mixed_dir path_entry.location.children.each do |child| md=/\A(.+)\.nkc\.rb\z/.match(File.basename(child)) if md return run_nkc(child,args) if md[1]==command else return run_external_file(child,args) if File.basename(child)==command and File.file? child end end else raise RuntimeError end end raise NoCommandError,_("%s: command not found")%[command] end |
.sessions ⇒ Object
an Array of all active sessions, in no significant order however, the order must not be changed during runtime, since the interfaces depend upon it
27 28 29 |
# File 'lib/naksh/session.rb', line 27 def Naksh.sessions @sessions end |
.shebang(file) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/old/old_executor.rb', line 63 def Naksh.shebang(file) begin file.rewind rescue end begin shebang_line=file.readline rescue raise ArgumentError,'Naksh.shebang requires one argument which responds to readline' end begin file.rewind rescue end return false unless /#!/.match(shebang_line) shebang_line.slice(2,shebang_line.length) end |
.suggestions(com_str) ⇒ Object
this should be a spell checker Naksh.suggestions(‘xml-cpy-editor’)#=>‘xml-copy-editor’ autocomplete is the next best thing
106 107 108 |
# File 'lib/naksh.rb', line 106 def Naksh.suggestions(com_str) Naksh.autocomplete(com_str) end |
.syntax ⇒ Object
52 53 54 |
# File 'lib/naksh/syntax.rb', line 52 def Naksh.syntax @syntax end |
.syntax=(new_syntax) ⇒ Object
set the current syntax ruleset currently no way to combine syntax rulesets except by method overwriting eg., you could define a command ‘ren’ which joins it’s arguments and executes them with the Ren interpreter
47 48 49 |
# File 'lib/naksh/syntax.rb', line 47 def Naksh.syntax=(new_syntax) @syntax=new_syntax end |