cmd_tools 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,14 +1,22 @@
1
- = Executables
2
- == +tsh+
1
+ = CmdTools
2
+ == What is this?
3
+ Simple small command line utilities.
4
+ == Executables
5
+ === +tsh+
3
6
  *rm* alternative. Move files and directories into ~/.myTrash with +TIME_NOW+. prefix.
4
- === Usage
5
- > tsh file1 file2 *~ dir1 dir2 1206??_photo
6
- == +bak+
7
- Back up files and directories of current directory into ./bak_since_SOME_NUMBERES directory with bak.+TIME_NOW+. prefix.
8
- === Usage
9
- > bak file1 file2 *~ dir1 dir2 1206??_photo
10
- == +cmd_tools_emacs_launcher_for_alternate_editor_of_emacsclient+
11
- Launch +emacs+ by using +spawn+. This should be usefull when using +emacsclient+.
12
- === Usage
13
- alias e='emacsclient -a cmd_tools_emacs_launcher_for_alternate_editor_of_emacsclient -t'
14
- alias em='emacsclient -a cmd_tools_emacs_launcher_for_alternate_editor_of_emacsclient -n'
7
+ ==== Usage
8
+ tsh file1 file2 *~ dir1 dir2 1206??_photo
9
+ === +bak+
10
+ Back up files and directories within current directory into ./bak_since_SOME_NUMBERES directory with bak.+TIME_NOW+. prefix.
11
+ ==== Usage
12
+ bak file1 file2 *~ dir1 dir2 1206??_photo
13
+ === +cmd_tools_emacs_launcher_for_alternate_editor_of_emacsclient+
14
+ Deleted: please use +emacs_launcher_(g|c)ui+.
15
+ === +emacs_launcher_(g|c)ui+
16
+ Launch emacs in (G|C)UI mode.
17
+ 1. If emacs daemon is not running, start a new daemon.
18
+ 2. If GUI mode and no frame exist, create a new frame.
19
+ 3. Open +files+ by emacsclient in (G|C)UI mode.
20
+ ==== Usage
21
+ alias em='emacs_launcher_gui'
22
+ alias e='emacs_launcher_cui'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "cmd_tools"
4
+ ::CmdTools::Bin::EmacsLauncher.run(:cui, ARGV)
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "cmd_tools"
4
+ ::CmdTools::Bin::EmacsLauncher.run(:gui, ARGV)
data/cmd_tools.gemspec CHANGED
@@ -11,9 +11,22 @@ Gem::Specification.new do |s|
11
11
 
12
12
  s.add_development_dependency 'ruby_patch', '~> 0.3'
13
13
  s.author = 'kshramt'
14
- s.description = "Command line tools. tsh: mv to ~/.myTrash. bak: bakup."
14
+ s.description = <<-EOS
15
+ Command line tools:
16
+ tsh: mv files to ~/.myTrash.
17
+ bak: backup files.
18
+ emacs_daemon: launch `emacs --daemon'.
19
+ EOS
15
20
  s.executables << 'bak'
16
21
  s.executables << 'tsh'
17
- s.executables << 'cmd_tools_emacs_launcher_for_alternate_editor_of_emacsclient'
22
+ s.executables << 'emacs_launcher_gui'
23
+ s.executables << 'emacs_launcher_cui'
24
+ s.post_install_message = <<-EOS
25
+
26
+ # CmdTools.
27
+ alias em='emacs_launcher_gui'
28
+ alias e='emacs_launcher_cui'
29
+
30
+ EOS
18
31
  s.required_ruby_version = '~> 1.9'
19
32
  end
@@ -0,0 +1,41 @@
1
+ module CmdTools
2
+ module Bin
3
+ module EmacsLauncher
4
+ require 'ruby_patch'
5
+ extend ::RubyPatch::AutoLoad
6
+
7
+ # Open +files+ by +mode+ (:gui/:cui) mode.
8
+ # Launch emacs daemon if necessary.
9
+ # Create new frame if necessary.
10
+ # You can edit ~/.config/cmd_tools/config.yaml to specify an emacs executable.
11
+ # For example, if you are a Mac user who uses MacPorts, following modification will be useful.
12
+ # - :emacs: emacs
13
+ # + :emacs: /Applications/MacPorts/Emacs.app/Contents/MacOS/Emacs
14
+ def self.run(mode, *files)
15
+ system "#{::CmdTools::Config.emacs} --daemon" unless self.daemon_running?
16
+
17
+ files = files.flatten.join(' ')
18
+ case mode
19
+ when :gui
20
+ if self.number_of_frames <= 1 # emacs daemon has one (invisible) frame.
21
+ system "emacsclient -c -n #{files}"
22
+ else
23
+ system "emacsclient -n #{files}"
24
+ end
25
+ when :cui
26
+ system "emacsclient -t #{files}"
27
+ else
28
+ raise ArgumentError, "Unknown mode: #{mode}"
29
+ end
30
+ end
31
+
32
+ def self.daemon_running?
33
+ system "emacsclient -e '()' >& /dev/null"
34
+ end
35
+
36
+ def self.number_of_frames
37
+ `emacsclient -e "(length (visible-frame-list))" >& /dev/null`.to_i
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,33 @@
1
+ module CmdTools
2
+ module Config
3
+ require 'yaml'
4
+ require 'fileutils'
5
+ require 'ruby_patch'
6
+ extend ::RubyPatch::AutoLoad
7
+
8
+ CONFIG_DIR = File.join(ENV['HOME'], '.config/cmd_tools')
9
+ CONFIG_FILE = File.join(CONFIG_DIR, 'config.yaml')
10
+ CONFIG_DEFAULT = {
11
+ emacs: ENV['ALTERNATE_EDITOR'] || 'emacs',
12
+ }
13
+
14
+ # (Re)load config file.
15
+ def self.load
16
+ @config = if File.readable?(CONFIG_FILE)
17
+ CONFIG_DEFAULT.merge(YAML.load_file(CONFIG_FILE))
18
+ else
19
+ FileUtils.mkdir_p(CONFIG_DIR)
20
+ open(CONFIG_FILE, 'w').write(CONFIG_DEFAULT.to_yaml)
21
+ CONFIG_DEFAULT
22
+ end
23
+
24
+ self
25
+ end
26
+
27
+ def self.emacs
28
+ @config[:emacs]
29
+ end
30
+
31
+ self.load
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module CmdTools
2
- VERSION = '0.2.0'
2
+ VERSION = '1.0.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmd_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-15 00:00:00.000000000 Z
12
+ date: 2012-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby_patch
16
- requirement: &79803450 !ruby/object:Gem::Requirement
16
+ requirement: &2156832100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,29 +21,43 @@ dependencies:
21
21
  version: '0.3'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *79803450
25
- description: ! 'Command line tools. tsh: mv to ~/.myTrash. bak: bakup.'
24
+ version_requirements: *2156832100
25
+ description: ! "Command line tools:\n tsh: mv files to ~/.myTrash.\n bak: backup
26
+ files.\n emacs_daemon: launch `emacs --daemon'.\n"
26
27
  email:
27
28
  executables:
28
29
  - bak
29
30
  - tsh
30
- - cmd_tools_emacs_launcher_for_alternate_editor_of_emacsclient
31
+ - emacs_launcher_gui
32
+ - emacs_launcher_cui
31
33
  extensions: []
32
34
  extra_rdoc_files: []
33
35
  files:
34
36
  - README.rdoc
35
37
  - bin/bak
36
- - bin/cmd_tools_emacs_launcher_for_alternate_editor_of_emacsclient
38
+ - bin/emacs_launcher_cui
39
+ - bin/emacs_launcher_gui
37
40
  - bin/tsh
38
41
  - cmd_tools.gemspec
39
42
  - lib/cmd_tools.rb
40
43
  - lib/cmd_tools/bin.rb
41
44
  - lib/cmd_tools/bin/bak.rb
45
+ - lib/cmd_tools/bin/emacs_launcher.rb
42
46
  - lib/cmd_tools/bin/tsh.rb
47
+ - lib/cmd_tools/config.rb
43
48
  - lib/cmd_tools/version.rb
44
49
  homepage:
45
50
  licenses: []
46
- post_install_message:
51
+ post_install_message: ! '
52
+
53
+ # CmdTools.
54
+
55
+ alias em=''emacs_launcher_gui''
56
+
57
+ alias e=''emacs_launcher_cui''
58
+
59
+
60
+ '
47
61
  rdoc_options: []
48
62
  require_paths:
49
63
  - lib
@@ -61,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
75
  version: '0'
62
76
  requirements: []
63
77
  rubyforge_project:
64
- rubygems_version: 1.8.11
78
+ rubygems_version: 1.8.15
65
79
  signing_key:
66
80
  specification_version: 3
67
81
  summary: Command line tools.
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
3
- # cmd_tools_emacs_opener_for_alternate_editor_of_emacsclient can be used as:
4
- # alias e='emacsclient -a cmd_tools_emacs_opener_for_alternate_editor_of_emacsclient -t'
5
- # alias em='emacsclient -a cmd_tools_emacs_opener_for_alternate_editor_of_emacsclient -n'
6
-
7
- spawn("emacs #{ARGV.join(' ')}")