benry-unixcmd 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +207 -122
- data/benry-unixcmd.gemspec +25 -44
- data/doc/benry-unixcmd.html +894 -0
- data/doc/css/style.css +168 -0
- data/lib/benry/unixcmd.rb +3 -3
- data/test/run_all.rb +2 -2
- data/test/unixcmd_test.rb +6 -6
- metadata +9 -30
- data/Rakefile.rb +0 -113
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ff5113d6cd99d3a50101096451203ade6c1f482ee0445fb92c54b7be806a92b
|
4
|
+
data.tar.gz: 130e7f320428382759597309256c39e9a50d0f8ab8e81d1854949f722f29b99d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffd7cc9973ff041b2478a5dbdb7c79ce93daf7214389bb8f5bf6caa561f181614cc68b085b0d2377bb11cc855108989bbc3e6dae7dfc34ff3c593586d45176a7
|
7
|
+
data.tar.gz: 4d9e61b09b80a5299327fc491605c92ea9f655b9737fac4d137b48590e61cf3e73c4e467cacbd5fde4cc1c9a50080fcc3349856e6f7ca4a1adfd7e19600bbd5e
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,16 @@
|
|
1
|
-
|
2
|
-
========================
|
1
|
+
# Benry-UnixCmd
|
3
2
|
|
4
|
-
($Release: 0.9.
|
3
|
+
($Release: 0.9.1 $)
|
5
4
|
|
6
|
-
|
5
|
+
|
6
|
+
## What's this?
|
7
|
+
|
8
|
+
Benry-UnixCmd implements popular UNIX commands, like FileUtils,
|
9
|
+
but much better than it.
|
10
|
+
|
11
|
+
* Document: <https://kwatch.github.io/benry-ruby/benry-unixcmd.html>
|
12
|
+
* GitHub: <https://github.com/kwatch/benry-ruby/tree/main/benry-unixcmd>
|
13
|
+
* Changes: <https://github.com/kwatch/benry-ruby/blob/main/benry-unixcmd/CHANGES.md>
|
7
14
|
|
8
15
|
Features compared to FileUtils:
|
9
16
|
|
@@ -19,53 +26,54 @@ Features compared to FileUtils:
|
|
19
26
|
* provides `store` command which copies files recursively into target directory, keeping file path.
|
20
27
|
* provides `atomic_symlink!` command which switches symlink atomically.
|
21
28
|
|
22
|
-
(
|
29
|
+
(Benry-UnixCmd requires Ruby >= 2.3)
|
23
30
|
|
24
31
|
|
25
32
|
|
26
|
-
Table of Contents
|
27
|
-
=================
|
33
|
+
### Table of Contents
|
28
34
|
|
29
35
|
<!-- TOC -->
|
30
36
|
|
31
|
-
*
|
32
|
-
*
|
33
|
-
|
34
|
-
*
|
35
|
-
*
|
36
|
-
*
|
37
|
-
*
|
38
|
-
*
|
39
|
-
*
|
40
|
-
*
|
41
|
-
*
|
42
|
-
*
|
43
|
-
*
|
44
|
-
*
|
45
|
-
*
|
46
|
-
*
|
47
|
-
*
|
48
|
-
*
|
49
|
-
*
|
50
|
-
*
|
51
|
-
*
|
52
|
-
*
|
53
|
-
*
|
54
|
-
*
|
55
|
-
*
|
56
|
-
*
|
57
|
-
*
|
58
|
-
|
59
|
-
*
|
60
|
-
*
|
61
|
-
*
|
37
|
+
* [What's this?](#whats-this)
|
38
|
+
* [Install](#install)
|
39
|
+
* [Command Reference](#command-reference)
|
40
|
+
* [`echo`](#echo)
|
41
|
+
* [`echoback`](#echoback)
|
42
|
+
* [`cp`](#cp)
|
43
|
+
* [`mv`](#mv)
|
44
|
+
* [`rm`](#rm)
|
45
|
+
* [`mkdir`](#mkdir)
|
46
|
+
* [`rmdir`](#rmdir)
|
47
|
+
* [`ln`](#ln)
|
48
|
+
* [`atomic_symlink!`](#atomic_symlink)
|
49
|
+
* [`touch`](#touch)
|
50
|
+
* [`chmod`](#chmod)
|
51
|
+
* [`chown`](#chown)
|
52
|
+
* [`pwd`](#pwd)
|
53
|
+
* [`cd`](#cd)
|
54
|
+
* [`pushd`](#pushd)
|
55
|
+
* [`store`](#store)
|
56
|
+
* [`sys`](#sys)
|
57
|
+
* [`ruby`](#ruby)
|
58
|
+
* [`capture2`](#capture2)
|
59
|
+
* [`capture2e`](#capture2e)
|
60
|
+
* [`capture3`](#capture3)
|
61
|
+
* [`zip`](#zip)
|
62
|
+
* [`unzip`](#unzip)
|
63
|
+
* [`time`](#time)
|
64
|
+
* [FAQ](#faq)
|
65
|
+
* [Why `mv` or `cp` requires `to:` option?](#why-mv-or-cp-requires-to-option)
|
66
|
+
* [How to use in Rakefile?](#how-to-use-in-rakefile)
|
67
|
+
* [How to change prompt string?](#how-to-change-prompt-string)
|
68
|
+
* [How to make prompt colored?](#how-to-make-prompt-colored)
|
69
|
+
* [How to disable command echoback?](#how-to-disable-command-echoback)
|
70
|
+
* [License and Copyright](#license-and-copyright)
|
62
71
|
|
63
72
|
<!-- /TOC -->
|
64
73
|
|
65
74
|
|
66
75
|
|
67
|
-
Install
|
68
|
-
=======
|
76
|
+
## Install
|
69
77
|
|
70
78
|
```
|
71
79
|
$ gem install benry-unixcmd
|
@@ -77,26 +85,25 @@ File: ex1.rb
|
|
77
85
|
require 'benry/unixcmd' # !!!!!
|
78
86
|
include Benry::UnixCommand # !!!!!
|
79
87
|
|
80
|
-
output = capture2 "
|
81
|
-
|
88
|
+
output = capture2 "uname -srmp" # run command and return output
|
89
|
+
p output
|
82
90
|
```
|
83
91
|
|
84
92
|
Result:
|
85
93
|
|
86
94
|
```terminal
|
87
|
-
[localhost] ruby ex1.rb
|
88
|
-
$
|
95
|
+
[localhost]$ ruby ex1.rb
|
96
|
+
$ uname -srmp
|
97
|
+
"Darwin 22.5.0 arm64 arm\n"
|
89
98
|
```
|
90
99
|
|
91
100
|
|
92
101
|
|
93
|
-
Command Reference
|
94
|
-
=================
|
102
|
+
## Command Reference
|
95
103
|
|
96
104
|
|
97
105
|
|
98
|
-
`echo`
|
99
|
-
------
|
106
|
+
### `echo`
|
100
107
|
|
101
108
|
File: ex-echo1.rb
|
102
109
|
|
@@ -127,8 +134,7 @@ Options:
|
|
127
134
|
|
128
135
|
|
129
136
|
|
130
|
-
`echoback`
|
131
|
-
----------
|
137
|
+
### `echoback`
|
132
138
|
|
133
139
|
* `echoback "command"` prints `$ command` string into stdout.
|
134
140
|
* `echoback "command"` indents command if in block of `cd` or `pushd`.
|
@@ -163,8 +169,7 @@ $ cd -
|
|
163
169
|
|
164
170
|
|
165
171
|
|
166
|
-
`cp`
|
167
|
-
----
|
172
|
+
### `cp`
|
168
173
|
|
169
174
|
* `cp "x", "y"` copies `x` to new file `y'. Fails when `y` already exists.
|
170
175
|
* `cp! "x", "y"` is similar to above, but overwrites `y` even if it exists.
|
@@ -172,6 +177,7 @@ $ cd -
|
|
172
177
|
* `cp "x", "y", "dir"` will be error! (use `to: "dir"` instead.)
|
173
178
|
* Glob pattern such as `*`, `**`, `?`, and `{}` are available.
|
174
179
|
* (See [FAQ](#faq) about `to:` keyword option.)
|
180
|
+
* If you want to copy files with keeping directory structure, use `store` instead of `cp`.
|
175
181
|
|
176
182
|
<!--
|
177
183
|
File: ex-cp1.rb
|
@@ -202,8 +208,7 @@ Options:
|
|
202
208
|
|
203
209
|
|
204
210
|
|
205
|
-
`mv`
|
206
|
-
----
|
211
|
+
### `mv`
|
207
212
|
|
208
213
|
* `mv "x", "y"` renames `x` to `y`. Fails when `y` already exists.
|
209
214
|
* `mv! "x", "y"` is similar to above, but overwrites `y` even if it exists.
|
@@ -241,8 +246,7 @@ Options:
|
|
241
246
|
|
242
247
|
|
243
248
|
|
244
|
-
`rm`
|
245
|
-
----
|
249
|
+
### `rm`
|
246
250
|
|
247
251
|
* `rm "x", "y"` removes file `x` and `y`.
|
248
252
|
* `rm :r, "dir1"` removes directory recursively.
|
@@ -275,8 +279,7 @@ Options:
|
|
275
279
|
|
276
280
|
|
277
281
|
|
278
|
-
`mkdir`
|
279
|
-
-------
|
282
|
+
### `mkdir`
|
280
283
|
|
281
284
|
* `mkdir "x", "y"` creates `x` and `y` directories.
|
282
285
|
* `mkdir :p, "x/y/z"` creates `x/y/z` directory.
|
@@ -309,8 +312,7 @@ Options:
|
|
309
312
|
|
310
313
|
|
311
314
|
|
312
|
-
`rmdir`
|
313
|
-
-------
|
315
|
+
### `rmdir`
|
314
316
|
|
315
317
|
* `rmdir "x", "y"` removed empty directores.
|
316
318
|
* Raises error when directory not empty.
|
@@ -333,8 +335,7 @@ Options:
|
|
333
335
|
|
334
336
|
|
335
337
|
|
336
|
-
`ln`
|
337
|
-
----
|
338
|
+
### `ln`
|
338
339
|
|
339
340
|
* `ln "x", "y"` creates hard link.
|
340
341
|
* `ln :s, "x", "y"` creates symbolic link. Error if `y` already exists.
|
@@ -361,14 +362,13 @@ ln! :s, "foo1.txt", "dir/foo1.txt" # overwrites dir/foo1.txt if exists.
|
|
361
362
|
## create symbolic link into directory.
|
362
363
|
ln :s, "foo1.txt", to: "dir"
|
363
364
|
|
364
|
-
## error! use
|
365
|
+
## error! use ``to: "dir"`` instead.
|
365
366
|
ln :s, "foo1.txt", "dir"
|
366
367
|
```
|
367
368
|
|
368
369
|
|
369
370
|
|
370
|
-
`atomic_symlink!`
|
371
|
-
-----------------
|
371
|
+
### `atomic_symlink!`
|
372
372
|
|
373
373
|
* `atomic_symlink! "x", "y"` creates symbolic link atomically.
|
374
374
|
|
@@ -395,8 +395,7 @@ Options:
|
|
395
395
|
|
396
396
|
|
397
397
|
|
398
|
-
`touch`
|
399
|
-
-------
|
398
|
+
### `touch`
|
400
399
|
|
401
400
|
* `touch "x"` updates timestamp of file.
|
402
401
|
* `touch :r, "reffile", "x"` uses timestamp of `reffile` instead current timestamp.
|
@@ -424,8 +423,7 @@ Options:
|
|
424
423
|
|
425
424
|
|
426
425
|
|
427
|
-
`chmod`
|
428
|
-
-------
|
426
|
+
### `chmod`
|
429
427
|
|
430
428
|
* `chmod 0644, "x"` changes file permission.
|
431
429
|
* `chmod :R, "a+r", "dir"` changes permissions recursively.
|
@@ -448,14 +446,13 @@ chmod :R, 0644, "dir"
|
|
448
446
|
chmod :R, "a+r", "dir"
|
449
447
|
```
|
450
448
|
|
451
|
-
|
449
|
+
Options:
|
452
450
|
|
453
451
|
* `chmod :R` -- changes permissions recursively.
|
454
452
|
|
455
453
|
|
456
454
|
|
457
|
-
`chown`
|
458
|
-
-------
|
455
|
+
### `chown`
|
459
456
|
|
460
457
|
* `chown "user:group", "x", "y"` changes owner and group of files.
|
461
458
|
* `chown "user", "x", "y"` changes owner of files.
|
@@ -476,14 +473,13 @@ chown "user1", "file*.txt" # change owner
|
|
476
473
|
chown ":group1", "file*.txt" # change group
|
477
474
|
```
|
478
475
|
|
479
|
-
|
476
|
+
Options:
|
480
477
|
|
481
478
|
* `chown :R` -- changes owner and/or group recursively.
|
482
479
|
|
483
480
|
|
484
481
|
|
485
|
-
`pwd`
|
486
|
-
-----
|
482
|
+
### `pwd`
|
487
483
|
|
488
484
|
* `pwd()` prints current working directory path.
|
489
485
|
|
@@ -496,7 +492,106 @@ require 'benry/unixcmd'
|
|
496
492
|
include Benry::UnixCommand
|
497
493
|
|
498
494
|
## prints current working directory
|
499
|
-
pwd()
|
495
|
+
pwd() #=> /home/yourname (for example)
|
496
|
+
```
|
497
|
+
|
498
|
+
Options:
|
499
|
+
|
500
|
+
* (no options)
|
501
|
+
|
502
|
+
|
503
|
+
|
504
|
+
### `cd`
|
505
|
+
|
506
|
+
* `cd` changes current working directory.
|
507
|
+
* If block given, `cd` invokes block just after changing current directory,
|
508
|
+
and back to previous directory automatically.
|
509
|
+
* Within block argument, echoback indentation is increased.
|
510
|
+
* `chdir` is an alias to `cd`.
|
511
|
+
|
512
|
+
File: ex-cd1.rb
|
513
|
+
|
514
|
+
```ruby
|
515
|
+
require 'benry/unixcmd'
|
516
|
+
include Benry::UnixCommand
|
517
|
+
|
518
|
+
## change directory, invoke block, and back to previous directory.
|
519
|
+
pwd() #=> /home/yourname (for example)
|
520
|
+
cd "/tmp" do
|
521
|
+
pwd() #=> /tmp
|
522
|
+
end
|
523
|
+
pwd() #=> /home/yourname (for example)
|
524
|
+
|
525
|
+
## just change directory
|
526
|
+
cd "/tmp"
|
527
|
+
pwd() #=> /tmp
|
528
|
+
```
|
529
|
+
|
530
|
+
Result:
|
531
|
+
|
532
|
+
```terminal
|
533
|
+
[localhost]$ ruby ex-cd1.rb
|
534
|
+
$ pwd
|
535
|
+
/home/yourname
|
536
|
+
$ cd /tmp
|
537
|
+
$ pwd
|
538
|
+
/tmp
|
539
|
+
$ cd -
|
540
|
+
$ pwd
|
541
|
+
/home/yourname
|
542
|
+
$ cd /tmp
|
543
|
+
$ pwd
|
544
|
+
/tmp
|
545
|
+
```
|
546
|
+
|
547
|
+
Options:
|
548
|
+
|
549
|
+
* (no options)
|
550
|
+
|
551
|
+
|
552
|
+
|
553
|
+
### `pushd`
|
554
|
+
|
555
|
+
* `pushd` changes current directory, invokes block, and back to previous directory.
|
556
|
+
* `pushd` requires block argument. `cd` also takes block argument but it is an optional.
|
557
|
+
* Within block argument, echoback indentation is increased.
|
558
|
+
|
559
|
+
File: ex-pushd1.rb
|
560
|
+
|
561
|
+
```ruby
|
562
|
+
require 'benry/unixcmd'
|
563
|
+
include Benry::UnixCommand
|
564
|
+
|
565
|
+
## change directory, invoke block, and back to previous directory.
|
566
|
+
pwd() #=> /home/yourname (for example)
|
567
|
+
pushd "/var" do
|
568
|
+
pwd() #=> /var
|
569
|
+
pushd "tmp" do
|
570
|
+
pwd() #=> /var/tmp
|
571
|
+
end
|
572
|
+
pwd() #=> /var
|
573
|
+
end
|
574
|
+
pwd() #=> /home/yourname (for example)
|
575
|
+
```
|
576
|
+
|
577
|
+
Result:
|
578
|
+
|
579
|
+
```terminal
|
580
|
+
[localhost]$ ruby ex-pushd1.rb
|
581
|
+
$ pwd
|
582
|
+
/home/yourname
|
583
|
+
$ pushd /var
|
584
|
+
$ pwd
|
585
|
+
/var
|
586
|
+
$ pushd tmp
|
587
|
+
$ pwd
|
588
|
+
/var/tmp
|
589
|
+
$ popd # back to /var
|
590
|
+
$ pwd
|
591
|
+
/var
|
592
|
+
$ popd # back to /home/yourname
|
593
|
+
$ pwd
|
594
|
+
/home/yourname
|
500
595
|
```
|
501
596
|
|
502
597
|
Options:
|
@@ -505,8 +600,7 @@ Options:
|
|
505
600
|
|
506
601
|
|
507
602
|
|
508
|
-
`store`
|
509
|
-
-------
|
603
|
+
### `store`
|
510
604
|
|
511
605
|
* `store "x", "y", to: "dir", ` copies files under `x` and `y` to `dir` keeping file path.
|
512
606
|
For example, `x/foo/bar.rb` will be copied as `dir/x/foo/bar.rb`.
|
@@ -522,6 +616,9 @@ include Benry::UnixCommand
|
|
522
616
|
|
523
617
|
## copies files into builddir, keeping file path
|
524
618
|
store "lib/**/*.rb", "test/**/*.rb", to: "builddir"
|
619
|
+
|
620
|
+
## `store()` is similar to unix `tar` command.
|
621
|
+
## $ tar cf - lib/**/*.rb test/**/*.rb | (cd builddir; tar xf -)
|
525
622
|
```
|
526
623
|
|
527
624
|
Options:
|
@@ -532,8 +629,7 @@ Options:
|
|
532
629
|
|
533
630
|
|
534
631
|
|
535
|
-
`sys`
|
536
|
-
-----
|
632
|
+
### `sys`
|
537
633
|
|
538
634
|
* `sys "ls -al"` runs `ls -al` command.
|
539
635
|
* `sys` raises error when command failed.
|
@@ -550,7 +646,7 @@ File: ex-sys1.rb
|
|
550
646
|
require 'benry/unixcmd'
|
551
647
|
include Benry::UnixCommand
|
552
648
|
|
553
|
-
## run
|
649
|
+
## run ``ls`` command
|
554
650
|
sys "ls foo.txt" # may raise error when command failed
|
555
651
|
sys! "ls foo.txt" # ignore error even when command filed
|
556
652
|
|
@@ -568,8 +664,7 @@ Options:
|
|
568
664
|
|
569
665
|
|
570
666
|
|
571
|
-
`ruby`
|
572
|
-
------
|
667
|
+
### `ruby`
|
573
668
|
|
574
669
|
* `ruby "...."` is almost same as `sys "ruby ...."`.
|
575
670
|
* `RbConfig.ruby` is used as ruby command path.
|
@@ -595,13 +690,12 @@ Options:
|
|
595
690
|
|
596
691
|
|
597
692
|
|
598
|
-
`capture2`
|
599
|
-
----------
|
693
|
+
### `capture2`
|
600
694
|
|
601
695
|
* `capture2 "ls -al"` runs `ls -al` and returns output of the command.
|
602
696
|
* `capture2 "cat -n", stdin_data: "A\nB\n"` run `cat -n` command and uses `"A\nB\n"` as stdin data.
|
603
|
-
* `
|
604
|
-
* `
|
697
|
+
* `caputre2 "ls foo"` will raise error when command failed.
|
698
|
+
* `caputre2! "ls foo"` ignores error even when command failed, and returns command output and process status object.
|
605
699
|
* `capture2()` invokes `Popen3.capture2()` internally. All keyword arguments are available.
|
606
700
|
|
607
701
|
<!--
|
@@ -613,9 +707,9 @@ require 'benry/unixcmd'
|
|
613
707
|
include Benry::UnixCommand
|
614
708
|
|
615
709
|
## run command and get output of the command.
|
616
|
-
output = capture2 "ls -l foo.txt"
|
617
|
-
output, process_status = capture2 "ls -l foot.xt" # ignore error even command failed
|
618
|
-
puts process_status.exitstatus
|
710
|
+
output = capture2 "ls -l foo.txt" # error if command failed
|
711
|
+
output, process_status = capture2! "ls -l foot.xt" # ignore error even command failed
|
712
|
+
puts process_status.exitstatus #=> 1
|
619
713
|
|
620
714
|
## run command with stdin data.
|
621
715
|
input = "AA\nBB\nCC\n"
|
@@ -628,8 +722,7 @@ Options:
|
|
628
722
|
|
629
723
|
|
630
724
|
|
631
|
-
`capture2e`
|
632
|
-
-----------
|
725
|
+
### `capture2e`
|
633
726
|
|
634
727
|
* almost same as `capture2`, but output contains both stdout and stderr.
|
635
728
|
|
@@ -653,10 +746,9 @@ Options:
|
|
653
746
|
|
654
747
|
|
655
748
|
|
656
|
-
`capture3`
|
657
|
-
----------
|
749
|
+
### `capture3`
|
658
750
|
|
659
|
-
* almost same as `
|
751
|
+
* almost same as `capture2`, but returns both stdout output and stderr output.
|
660
752
|
|
661
753
|
<!--
|
662
754
|
File: ex-capture3.rb
|
@@ -682,8 +774,7 @@ Options:
|
|
682
774
|
|
683
775
|
|
684
776
|
|
685
|
-
`zip`
|
686
|
-
-----
|
777
|
+
### `zip`
|
687
778
|
|
688
779
|
* `zip "foo.zip", "file1", "file2"` creates new zip file `foo.zip`.
|
689
780
|
* `zip :r, "foo.zip", "dir1"` adds files under `dir1` into zip file recursively.
|
@@ -692,7 +783,8 @@ Options:
|
|
692
783
|
* `zip :'0'` doesn't compress files.
|
693
784
|
* `zip :'1'` compress files in best speed.
|
694
785
|
* `zip :'9'` compress files in best compression level.
|
695
|
-
* `zip` and `zip!`
|
786
|
+
* `zip` and `zip!` loads `rubyzip` gem automatically. You must install it by yourself.
|
787
|
+
* (`rubyzip` gem is necessary ONLY when `zip` or `zip!` command is invoked.)
|
696
788
|
* `zip` and `zip!` doesn't support absolute path.
|
697
789
|
|
698
790
|
<!--
|
@@ -722,8 +814,7 @@ Options:
|
|
722
814
|
|
723
815
|
|
724
816
|
|
725
|
-
`unzip`
|
726
|
-
-------
|
817
|
+
### `unzip`
|
727
818
|
|
728
819
|
* `unzip "foo.zip"` extracts files in zip file into current directory.
|
729
820
|
* `unzip :d, "dir1", "foo.zip"` extracts files under `dir1`.
|
@@ -731,7 +822,8 @@ Options:
|
|
731
822
|
* `unzip "foo.zip"` will be error if extracting file already exists.
|
732
823
|
* `unzip! "foo.zip"` will overwrite existing files.
|
733
824
|
* `unzip "foo.txt", "file1", "file2"` extracts only `file1` and `file2`.
|
734
|
-
* `zunip` and `unzip!`
|
825
|
+
* `zunip` and `unzip!` loads `rubyzip` gem automatically. You must install it by yourself.
|
826
|
+
* (`rubyzip` gem is necessary ONLY when `unzip` or `unzip!` command is invoked.)
|
735
827
|
* `unzip` and `unzip!` doesn't support absolute path.
|
736
828
|
|
737
829
|
<!--
|
@@ -758,8 +850,7 @@ Options:
|
|
758
850
|
|
759
851
|
|
760
852
|
|
761
|
-
`time`
|
762
|
-
------
|
853
|
+
### `time`
|
763
854
|
|
764
855
|
* `time do ... end` invokes block and prints elapsed time into stderr.
|
765
856
|
|
@@ -770,7 +861,7 @@ require 'benry/unixcmd'
|
|
770
861
|
include Benry::UnixCommand
|
771
862
|
|
772
863
|
time do
|
773
|
-
|
864
|
+
sys "zip -qr9 dir1.zip dir1"
|
774
865
|
end
|
775
866
|
```
|
776
867
|
|
@@ -785,13 +876,11 @@ $ zip -qr9 dir1.zip dir1
|
|
785
876
|
|
786
877
|
|
787
878
|
|
788
|
-
FAQ
|
789
|
-
====
|
879
|
+
## FAQ
|
790
880
|
|
791
881
|
|
792
882
|
|
793
|
-
Why `mv` or `cp` requires `to:` option?
|
794
|
-
---------------------------------------
|
883
|
+
### Why `mv` or `cp` requires `to:` option?
|
795
884
|
|
796
885
|
Because UNIX command has bad interface which causes unexpected result.
|
797
886
|
|
@@ -819,8 +908,7 @@ In the same reason, `cp()` and `ln()` of Benry::UnixCommand also requires `to:`
|
|
819
908
|
|
820
909
|
|
821
910
|
|
822
|
-
How to use in Rakefile?
|
823
|
-
-----------------------
|
911
|
+
### How to use in Rakefile?
|
824
912
|
|
825
913
|
File: Rakefile
|
826
914
|
|
@@ -830,6 +918,7 @@ include Benry::UnixCommand # !!!!!
|
|
830
918
|
Rake::DSL.prepend Benry::UnixCommand # !!!!!
|
831
919
|
|
832
920
|
task :example do
|
921
|
+
## invoke commands defined in Benry::UnixCommand, not in Rake nor fileutils.rb
|
833
922
|
mkdir :p, "foo/bar/baz"
|
834
923
|
here = Dir.pwd()
|
835
924
|
pushd "foo/bar/baz" do
|
@@ -852,8 +941,7 @@ $ popd # back to /home/yourname
|
|
852
941
|
|
853
942
|
|
854
943
|
|
855
|
-
How to change prompt string?
|
856
|
-
----------------------------
|
944
|
+
### How to change prompt string?
|
857
945
|
|
858
946
|
File: ex-prompt1.rb
|
859
947
|
|
@@ -865,7 +953,7 @@ def prompt() # !!!!!
|
|
865
953
|
"myname@localhost>" # !!!!!
|
866
954
|
end # !!!!!
|
867
955
|
|
868
|
-
|
956
|
+
sys "date"
|
869
957
|
```
|
870
958
|
|
871
959
|
Result:
|
@@ -878,8 +966,7 @@ Wed Jan 15 20:23:07 UTC 2021
|
|
878
966
|
|
879
967
|
|
880
968
|
|
881
|
-
How to make prompt colored?
|
882
|
-
---------------------------
|
969
|
+
### How to make prompt colored?
|
883
970
|
|
884
971
|
<!--
|
885
972
|
File: ex-prompt2.rb
|
@@ -900,13 +987,12 @@ def prompt()
|
|
900
987
|
#"\e[0;37m#{s}\e[0m" # white
|
901
988
|
end
|
902
989
|
|
903
|
-
|
990
|
+
sys "date"
|
904
991
|
```
|
905
992
|
|
906
993
|
|
907
994
|
|
908
|
-
How to disable command echoback?
|
909
|
-
--------------------------------
|
995
|
+
### How to disable command echoback?
|
910
996
|
|
911
997
|
File: ex-quiet1.rb
|
912
998
|
|
@@ -916,7 +1002,7 @@ include Benry::UnixCommand
|
|
916
1002
|
|
917
1003
|
BENRY_ECHOBACK = false # !!!!!
|
918
1004
|
|
919
|
-
|
1005
|
+
sys "date"
|
920
1006
|
```
|
921
1007
|
|
922
1008
|
Result:
|
@@ -928,9 +1014,8 @@ Wed Jan 1 22:29:55 UTC 2020 # no echoback, only output
|
|
928
1014
|
|
929
1015
|
|
930
1016
|
|
931
|
-
License and Copyright
|
932
|
-
=====================
|
1017
|
+
## License and Copyright
|
933
1018
|
|
934
1019
|
$License: MIT License $
|
935
1020
|
|
936
|
-
$Copyright: copyright(c) 2021
|
1021
|
+
$Copyright: copyright(c) 2021 kwatch@gmail.com $
|