Class: Autostart
- Inherits:
-
Object
- Object
- Autostart
- Defined in:
- lib/autostart/autostart.rb,
lib/autostart/constants.rb,
lib/autostart/version/version.rb
Overview
#
require ‘autostart/version/version.rb’
#
Constant Summary collapse
- DEFAULT_INPUT =
#
DEFAULT_INPUT
#
'xfce'
- DEFAULT_COLOUR =
#
DEFAULT_COLOUR
#
::Colours::GREEN
- HOME_DIR =
#
HOME_DIR
#
"#{ENV['HOME']}/"
- KDE_AUTOSTART =
#
KDE_AUTOSTART
#
'~/.kde/Autostart/'
- LINUX =
#
LINUX
#
ENV['LINUX'].to_s
- SYSBIN =
#
SYSBIN
#
ENV['MY_SYSBIN'].to_s
- SOFFICE_BINARY =
#
SOFFICE_BINARY
For libreoffice.
#
'/opt/libreoffice/program/soffice'
- FIREFOX_BINARY =
#
FIREFOX_BINARY
#
'/Programs/Firefox/Current/firefox'
- ARRAY_SYMLINK_THESE_ENTRIES_FOR_KDE =
#
ARRAY_SYMLINK_THESE_ENTRIES_FOR_KDE
Which entries should be symlinked for KDE.
If you do not want to have this entry, simply remove it from the constant.
#
[ FIREFOX_BINARY, "#{LINUX}/SHELL/SCRIPTS/konsole.sh", SYSBIN+'/bluefish', SYSBIN+'/pidgin', SOFFICE_BINARY, ]
- ARRAY_SYMLINK_THESE_ENTRIES_FOR_XFCE =
#
ARRAY_SYMLINK_THESE_ENTRIES_FOR_XFCE
Use xchat, bluefish, konsole and mrxvt.
#
[ # SYSBIN+'/bluefish',xchat SYSBIN+'/bluefish', SYSBIN+'/konsole', SYSBIN+'/mrxvt' ] << FIREFOX_BINARY
- VERSION =
#
Autostart::VERSION
#
'1.0.21'
Class Method Summary collapse
-
.autostart_kde ⇒ Object
# === Autostart.autostart_kde ========================================================================= #.
-
.run(i = ARGV) ⇒ Object
# === Autostart.run ========================================================================= #.
Instance Method Summary collapse
-
#autostart_icewm(i = ARRAY_SYMLINK_THESE_ENTRIES_FOR_XFCE) ⇒ Object
# === autostart_icewm ========================================================================= #.
-
#autostart_kde ⇒ Object
# === autostart_kde (kde tag).
-
#autostart_mate(use_these_programs = :load_from_the_default_yaml_file) ⇒ Object
# === autostart_mate ========================================================================= #.
-
#autostart_what(i = DEFAULT_INPUT) ⇒ Object
(also: #run)
# === autostart_what ========================================================================= #.
-
#autostart_xfce(i = ARRAY_SYMLINK_THESE_ENTRIES_FOR_XFCE) ⇒ Object
# === autostart_xfce (xfce tag).
-
#consider_reporting_missing_entries_to_the_user ⇒ Object
# === consider_reporting_missing_entries_to_the_user ========================================================================= #.
-
#copy(from, to) ⇒ Object
# === copy ========================================================================= #.
-
#initialize(what = 'default') ⇒ Autostart
constructor
# === initialize ========================================================================= #.
-
#mkdir(i) ⇒ Object
(also: #ensure_that_this_directory_exists)
# === mkdir ========================================================================= #.
-
#orange(i) ⇒ Object
# === orange ========================================================================= #.
-
#output_header ⇒ Object
# === output_header (cliner tag, liner tag) ========================================================================= #.
-
#red ⇒ Object
# === red ========================================================================= #.
-
#remove_file(i) ⇒ Object
# === remove_file ========================================================================= #.
-
#reset ⇒ Object
# === reset ========================================================================= #.
-
#show_header(for_this_program = :xfce) ⇒ Object
# === show_header ========================================================================= #.
-
#show_help ⇒ Object
# === show_help ========================================================================= #.
-
#symlink(i) ⇒ Object
# === symlink.
Constructor Details
#initialize(what = 'default') ⇒ Autostart
#
initialize
#
39 40 41 42 43 44 |
# File 'lib/autostart/autostart.rb', line 39 def initialize( what = 'default' ) reset autostart_what(what) if what end |
Class Method Details
.autostart_kde ⇒ Object
#
Autostart.autostart_kde
#
324 325 326 |
# File 'lib/autostart/autostart.rb', line 324 def self.autostart_kde new(:kde) end |
.run(i = ARGV) ⇒ Object
#
Autostart.run
#
331 332 333 |
# File 'lib/autostart/autostart.rb', line 331 def self.run(i = ARGV) new(i) end |
Instance Method Details
#autostart_icewm(i = ARRAY_SYMLINK_THESE_ENTRIES_FOR_XFCE) ⇒ Object
#
autostart_icewm
#
290 291 292 293 294 295 296 297 298 299 |
# File 'lib/autostart/autostart.rb', line 290 def autostart_icewm( i = ARRAY_SYMLINK_THESE_ENTRIES_FOR_XFCE ) show_header :icewm home_dir = HOME_DIR+'.config/autostart' mkdir home_dir i.each {|entry| symlink("#{entry} #{home_dir}") } end |
#autostart_kde ⇒ Object
#
autostart_kde (kde tag)
To invoke this method, do:
autostart --kde
#
201 202 203 204 205 206 207 208 209 210 |
# File 'lib/autostart/autostart.rb', line 201 def autostart_kde show_header :kde # mkdir HSS['KDE_AUTOSTART'] ensure_that_this_directory_exists KDE_AUTOSTART mkdir '~/.kde/share/config/' copy '$LINUX/KDE/konsolerc','~/.kde/share/config/' ARRAY_SYMLINK_THESE_ENTRIES_FOR_KDE.each {|entry| symlink(entry+' $KDE_AUTOSTART') } end |
#autostart_mate(use_these_programs = :load_from_the_default_yaml_file) ⇒ Object
#
autostart_mate
#
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/autostart/autostart.rb', line 215 def autostart_mate( use_these_programs = :load_from_the_default_yaml_file ) case use_these_programs # ======================================================================= # # === :load_from_the_default_yaml_file # ======================================================================= # when :load_from_the_default_yaml_file, :default YAML.load_file( '/home/x/programming/ruby/src/roebe/lib/roebe/yaml/'\ 'autostart_these_programs.yml' ) end if use_these_programs and File.exist?(use_these_programs) use_these_programs = YAML.load_file(use_these_programs) end show_header :mate home_dir = HOME_DIR+'.config/autostart' mkdir home_dir use_these_programs.each {|this_file| Roebe::CreateDesktopFile.new(this_file) } end |
#autostart_what(i = DEFAULT_INPUT) ⇒ Object Also known as: run
#
autostart_what
#
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/autostart/autostart.rb', line 243 def autostart_what(i = DEFAULT_INPUT) i = DEFAULT_INPUT if i.nil? i = i.first if i.is_a? Array # Fetch first entry if it is an Array. case i.to_s # case tag # ======================================================================= # # === autostart help # ======================================================================= # when /^-?-?help/ show_help exit # ======================================================================= # # === autostart mate # ======================================================================= # when /^-?-?mate$/ autostart_mate # ======================================================================= # # === autostart icewm # ======================================================================= # when /^-?-?icewm$/ autostart_icewm # ======================================================================= # # === autostart xfce # ======================================================================= # when /^-?-?xfce$/,'default','' # This is the default since August 2013. autostart_xfce # ======================================================================= # # === autostart kde # ======================================================================= # when /^-?-?kde$/ autostart_kde else opn; e 'Not found `'+simp(i)+'` in the list of available entries.' opn; e 'It is probably not registered.' end consider_reporting_missing_entries_to_the_user end |
#autostart_xfce(i = ARRAY_SYMLINK_THESE_ENTRIES_FOR_XFCE) ⇒ Object
#
autostart_xfce (xfce tag)
This will usually default to programs such as:
xchat, bluefish, konsole and mrxvt.
#
309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/autostart/autostart.rb', line 309 def autostart_xfce( i = ARRAY_SYMLINK_THESE_ENTRIES_FOR_XFCE ) show_header :xfce # home_dir = '~/.config/autostart' home_dir = HOME_DIR+'.config/autostart' mkdir home_dir i.each {|entry| symlink("#{entry} #{home_dir}") } end |
#consider_reporting_missing_entries_to_the_user ⇒ Object
#
consider_reporting_missing_entries_to_the_user
#
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/autostart/autostart.rb', line 60 def consider_reporting_missing_entries_to_the_user unless @array_these_symlinks_were_not_found.empty? e opn; e 'We did find some missing entries. Perhaps you '\ 'may wish to correct these:' e @array_these_symlinks_were_not_found.each {|entry| e simp(" #{entry}") }; e end end |
#copy(from, to) ⇒ Object
#
copy
#
98 99 100 101 102 103 104 |
# File 'lib/autostart/autostart.rb', line 98 def copy(from, to) from = ConvertGlobalEnv[from] if from.include? '$' to = ConvertGlobalEnv[to] if to.include? '$' from = File.(from) to = File.(to) FileUtils.copy(from, to) end |
#mkdir(i) ⇒ Object Also known as: ensure_that_this_directory_exists
#
mkdir
#
75 76 77 78 |
# File 'lib/autostart/autostart.rb', line 75 def mkdir(i) i = File.(i) if i.include? '~' # If includes ~, use File.expand_path FileUtils.mkdir_p(i) unless File.exist?(i) end |
#orange(i) ⇒ Object
#
orange
#
283 284 285 |
# File 'lib/autostart/autostart.rb', line 283 def orange(i) ::Colours.orange(i) end |
#output_header ⇒ Object
#
output_header (cliner tag, liner tag)
#
174 175 176 |
# File 'lib/autostart/autostart.rb', line 174 def output_header e '=' * 80 end |
#red ⇒ Object
#
red
#
91 92 93 |
# File 'lib/autostart/autostart.rb', line 91 def red ::Colours::RED end |
#remove_file(i) ⇒ Object
#
remove_file
#
83 84 85 86 |
# File 'lib/autostart/autostart.rb', line 83 def remove_file(i) opn; e red+'Removing file '+sfile(i)+red+' now.' if File.exist?(i) File.delete(i) if File.file?(i) end |
#reset ⇒ Object
#
reset
#
49 50 51 52 53 54 55 |
# File 'lib/autostart/autostart.rb', line 49 def reset @array_these_symlinks_were_not_found = [] # ======================================================================= # # === @be_verbose # ======================================================================= # @be_verbose = true end |
#show_header(for_this_program = :xfce) ⇒ Object
#
show_header
#
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/autostart/autostart.rb', line 155 def show_header( for_this_program = :xfce ) case for_this_program # === :xfce when :xfce for_this_program = 'XFCE' # === :kde when :kde for_this_program = 'KDE' end output_header opn; e "Autostart for #{orange(for_this_program)}." output_header end |
#show_help ⇒ Object
#
show_help
#
181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/autostart/autostart.rb', line 181 def show_help e 'This class (class Autostart) allows you to "autostart" some '\ 'applications in different DE/WMs.' e e 'Available autostart actions are:' e e ' - xfce' e ' - kde' e ' - mate' e end |
#symlink(i) ⇒ Object
#
symlink
This method accepts only one argument and will split it based on ‘ ’.
File.symlink(real_existing_location, new_location)
#
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/autostart/autostart.rb', line 114 def symlink(i) # Expects string input. real_existing_location, new_location = i.split ' ' if real_existing_location.include? '$' # We solve this very simply without regex. last_position = real_existing_location.index('/') real_value = ENV[real_existing_location[1, last_position-1]].dup real_existing_location = real_value+real_existing_location[last_position..-1] end if new_location.include? '$' new_location = ConvertGlobalEnv.convert new_location end new_location = File.(new_location) if new_location.include? '~' filename = File.basename(real_existing_location) new_location << '/'+filename if File.symlink?(new_location) readlink = File.readlink(new_location) remove_file(readlink) unless File.exist?(readlink) end remove_file(new_location) if File.exist? new_location if File.exist?(real_existing_location) opn; e 'Trying to symlink '+sfile(real_existing_location)+ ' to '+sfile(new_location)+' now.' unless File.exist? new_location File.symlink(real_existing_location, new_location) else opn; e 'Can not symlink because '+sfile(new_location)+' does not exist.' end else if @be_verbose opn; e 'Trying to symlink '+sfile(real_existing_location)+ ' to '+sfile(new_location) opn; e 'but the file '+sfile(real_existing_location)+' does not '\ 'exist, thus we skip this action.' @array_these_symlinks_were_not_found << real_existing_location end end end |