Module: Snibbets::OS
- Defined in:
- lib/snibbets/os.rb
Class Method Summary collapse
-
.copy(text) ⇒ Object
Platform-agnostic copy command.
-
.darwin_open(file, app: nil) ⇒ Object
macOS open command.
-
.linux_open(file) ⇒ Object
Linux open command.
-
.open(file, app: nil) ⇒ Object
Platform-agnostic open command.
-
.paste ⇒ Object
Platform-agnostic paste command.
-
.win_open(file) ⇒ Object
Windows open command.
Class Method Details
.copy(text) ⇒ Object
Platform-agnostic copy command
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/snibbets/os.rb', line 11 def copy(text) os = RbConfig::CONFIG['target_os'] case os when /darwin.*/i `echo #{Shellwords.escape(text.uncolor)} | pbcopy` else if TTY::Which.exist?('xclip') `echo #{Shellwords.escape(text.uncolor)} | xclip -sel c` elsif TTY::Which.exist('xsel') `echo #{Shellwords.escape(text.uncolor)} | xsel -ib` else puts 'Copy not supported on this system, please install xclip or xsel.' end end end |
.darwin_open(file, app: nil) ⇒ Object
macOS open command
69 70 71 72 73 74 75 |
# File 'lib/snibbets/os.rb', line 69 def darwin_open(file, app: nil) if app `open -a "#{app}" #{Shellwords.escape(file)}` else `open #{Shellwords.escape(file)}` end end |
.linux_open(file) ⇒ Object
Linux open command
91 92 93 94 95 96 97 |
# File 'lib/snibbets/os.rb', line 91 def linux_open(file) if TTY::Which.exist?('xdg-open') `xdg-open #{Shellwords.escape(file)}` else notify('{r}Unable to determine executable for `xdg-open`.') end end |
.open(file, app: nil) ⇒ Object
Platform-agnostic open command
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/snibbets/os.rb', line 51 def open(file, app: nil) os = RbConfig::CONFIG['target_os'] case os when /darwin.*/i darwin_open(file, app: app) when /mingw|mswin/i win_open(file) else linux_open(file) end end |
.paste ⇒ Object
Platform-agnostic paste command
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/snibbets/os.rb', line 30 def paste os = RbConfig::CONFIG['target_os'] case os when /darwin.*/i `pbpaste -pboard general -Prefer txt`.strip_newlines else if TTY::Which.exist?('xclip') `xclip -o -sel c`.strip_newlines elsif TTY::Which.exist('xsel') `xsel -ob`.strip_newlines else puts 'Paste not supported on this system, please install xclip or xsel.' end end end |
.win_open(file) ⇒ Object
Windows open command
82 83 84 |
# File 'lib/snibbets/os.rb', line 82 def win_open(file) `start #{Shellwords.escape(file)}` end |