Top Level Namespace

Defined Under Namespace

Modules: Kernel, NeverGonnaLetYouDown Classes: CmdDirWidget, CmdPanelCaptionWidget, CmdPanelWidget, CopyDlg, Exception, Fixnum, Integer, MkDirDlg, MoveDlg, Object, Pathname, RemoveDlg, Time

Constant Summary collapse

UNITS =

TODO: find another way

%W(kiB MiB GiB TiB).freeze
APP_NAME =
'unixcmd'
APP_VERSION =
'0.2.12'

Instance Method Summary collapse

Instance Method Details

#cmd_file_copy(files, srcdir, dstdir) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/unixcmd/cmd.rb', line 47

def cmd_file_copy(files, srcdir, dstdir)
  files_s = files.map do |file|
    file.to_s
  end

  dlg = CopyDlg.new files_s, dstdir.to_s
  res = dlg.run

  flags = ''

  flags << '-r ' if dlg.recursive?
  flags << '-a ' if dlg.archive?
  flags << '-v ' if dlg.verbose?
  flags.strip!

  dstdir = Pathname.new(dlg.dest)

  unless res == 0
    dlg.destroy
    return
  end

  cpthread = Thread.new do
    Dir.chdir(srcdir.expand_path.to_s) do
      $wnd.cmd "cp #{flags} #{files_s.join ' '} #{dstdir.to_s}"
    end
  end

  cpthread.abort_on_exception = true
  cpthread.join
  cpthread.exit

  dlg.destroy
end

#cmd_file_edit(file) ⇒ Object



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/unixcmd/cmd.rb', line 194

def cmd_file_edit(file)
  fullpath = file.expand_path

  return if fullpath.directory?

  if file.expand_path.directory?
    filetype = 'directory'
  else
    filetype = MIME::Types.of fullpath.to_s
    filetype = 'binary (undefined)' if filetype == nil || filetype.count == 0
    filetype = filetype[0].to_s if filetype.class == Array
  end

  editor = 'gvim'

  editor = $cfg['editors'][filetype] if $cfg['editors'].has_key? filetype

  $wnd.cmd "#{editor} #{file.to_s}"
end

#cmd_file_info(file) ⇒ Object



214
215
216
217
218
# File 'lib/unixcmd/cmd.rb', line 214

def cmd_file_info(file)
  dlg = FileInfoDlg.new file
  dlg.run
  dlg.destroy
end

#cmd_file_mkdir(dir) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/unixcmd/cmd.rb', line 145

def cmd_file_mkdir(dir)
  dlg = MkDirDlg.new
  res = dlg.run

  flags = ''

  flags << '-v ' if dlg.verbose?
  flags.strip!

  dirname = dlg.dirname

  unless res == 0
    dlg.destroy
    return
  end

  thread = Thread.new do
    Dir.chdir(dir.expand_path.to_s) do
      $wnd.cmd "mkdir #{flags} #{dirname}"
    end
  end

  thread.abort_on_exception = true
  thread.join
  thread.exit

  dlg.destroy
end

#cmd_file_move(files, srcdir, dstdir) ⇒ Object



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
# File 'lib/unixcmd/cmd.rb', line 82

def cmd_file_move(files, srcdir, dstdir)
  files_s = files.map do |file|
    file.to_s
  end

  dlg = MoveDlg.new files_s, dstdir
  res = dlg.run

  flags = ''

  flags << '-v ' if dlg.verbose?
  flags.strip!

  unless res == 0
    dlg.destroy
    return
  end

  mvthread = Thread.new do
    Dir.chdir(srcdir.expand_path.to_s) do
      puts $wnd.cmd "mv #{flags} #{files_s.join ' '} #{dstdir.to_s}"
    end
  end

  mvthread.abort_on_exception = true
  mvthread.join
  mvthread.exit

  dlg.destroy
end

#cmd_file_remove(files, dir) ⇒ Object



113
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
# File 'lib/unixcmd/cmd.rb', line 113

def cmd_file_remove(files, dir)
  files_s = files.map do |file|
    file.to_s
  end

  dlg = RemoveDlg.new files_s
  res = dlg.run

  flags = ''

  flags << '-r ' if dlg.recursive?
  flags << '-v ' if dlg.verbose?
  flags.strip!

  unless res == 0
    dlg.destroy
    return
  end

  thread = Thread.new do
    Dir.chdir(dir.expand_path.to_s) do
      $wnd.cmd "rm #{flags} #{files_s.join ' '}"
    end
  end

  thread.abort_on_exception = true
  thread.join
  thread.exit

  dlg.destroy
end

#cmd_file_view(file) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/unixcmd/cmd.rb', line 174

def cmd_file_view(file)
  fullpath = file.expand_path

  return if fullpath.directory?

  if file.expand_path.directory?
    filetype = 'directory'
  else
    filetype = MIME::Types.of fullpath.to_s
    filetype = 'binary (undefined)' if filetype == nil || filetype.count == 0
    filetype = filetype[0].to_s if filetype.class == Array
  end

  viewer = 'gview'

  viewer = $cfg['viewers'][filetype] if $cfg['viewers'].has_key? filetype

  $wnd.cmd "#{viewer} #{file.to_s}"
end