source_win_bat 0.2.0 → 0.3.0
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/bin/init_sw +20 -22
- data/lib/source_win_bat.rb +93 -14
- data/source_win_bat.gemspec +2 -2
- data/test/setcwd.cmd +1 -0
- data/test/test_ansicpchars.bash +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60ef7f12402da3cef3443161f97eef66b580182aa70c2ea20e2f936dc56f9cd3
|
4
|
+
data.tar.gz: 70f32f56ddb5aa0bdded6e72084bb977af84658b4dcabf3cbdc3e288cdc104e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87b0dda50fb66fac4b6c691bebf72d6549561e48092ce04945e083a4dca332ad5530c4bcf91ff43f7d8759d415ffef4789e3ab89f178ab142e00231c1617e698
|
7
|
+
data.tar.gz: 6aa26c86859b485d8033a01ddb5a72b73b5e07306a9b2326e762a63034e6ca11b377719de21694befaa6dd22d4e665b76a913dd87f4e7e97836f36c6ab48a4e6
|
data/bin/init_sw
CHANGED
@@ -10,36 +10,30 @@ if [[ `uname` != Linux && $? != 0 ]]; then
|
|
10
10
|
else
|
11
11
|
sw () {
|
12
12
|
local arg
|
13
|
+
local preserves_dump=
|
14
|
+
local shows_cmd=
|
15
|
+
local is_cmd_given=
|
13
16
|
local tmp_env tmp_macro tmp_cwd
|
14
17
|
local exitstatus
|
15
18
|
|
19
|
+
local opts=()
|
16
20
|
for arg in "$@"; do
|
17
21
|
if [[ "$arg" = "--" ]]; then
|
18
22
|
shift 1
|
19
23
|
break
|
20
24
|
elif [[ "$arg" =~ ^-+.+ ]]; then
|
21
25
|
case "$arg" in
|
22
|
-
"--
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
Sw options:
|
32
|
-
-help --help Show this help message
|
33
|
-
|
34
|
-
Examples:
|
35
|
-
sw echo test
|
36
|
-
sw somebat.bat
|
37
|
-
|
38
|
-
EOS
|
39
|
-
return ;;
|
26
|
+
"--preserve-dump" )
|
27
|
+
preserves_dump=0
|
28
|
+
opts+=( "$arg" )
|
29
|
+
;;
|
30
|
+
"--debug" )
|
31
|
+
preserves_dump=0
|
32
|
+
opts+=( "$arg" )
|
33
|
+
;;
|
40
34
|
* )
|
41
|
-
|
42
|
-
|
35
|
+
opts+=( "$arg" )
|
36
|
+
;;
|
43
37
|
esac
|
44
38
|
shift 1
|
45
39
|
else
|
@@ -50,7 +44,7 @@ EOS
|
|
50
44
|
tmp_env="$(mktemp)"
|
51
45
|
tmp_macro="$(mktemp)"
|
52
46
|
tmp_cwd="$(mktemp)"
|
53
|
-
ruby -W0 -e "require 'source_win_bat'; SourceWindowsBatch.new.main(ARGV)" "${tmp_env}" "${tmp_macro}" "${tmp_cwd}" "$@"
|
47
|
+
ruby -W0 -e "require 'source_win_bat'; SourceWindowsBatch.new.main(ARGV)" -- "${opts[@]}" -- "${tmp_env}" "${tmp_macro}" "${tmp_cwd}" "$@"
|
54
48
|
exitstatus=$?
|
55
49
|
if [[ -e "${tmp_env}" ]]; then
|
56
50
|
source "${tmp_env}"
|
@@ -62,7 +56,11 @@ EOS
|
|
62
56
|
source "${tmp_cwd}"
|
63
57
|
fi
|
64
58
|
|
65
|
-
|
59
|
+
if [[ -z $preserves_dump ]]; then
|
60
|
+
ruby -e "begin; File.delete('${tmp_env}', '${tmp_macro}', '${tmp_cwd}'); rescue Errno::ENOENT; end"
|
61
|
+
else
|
62
|
+
echo "SW: '${tmp_env}', '${tmp_macro}', '${tmp_cwd}' are preserved"
|
63
|
+
fi
|
66
64
|
return $exitstatus
|
67
65
|
}
|
68
66
|
fi
|
data/lib/source_win_bat.rb
CHANGED
@@ -6,18 +6,10 @@ require_relative 'unixcompatenv'
|
|
6
6
|
|
7
7
|
class SourceWindowsBatch
|
8
8
|
|
9
|
-
VERSION = "0.
|
9
|
+
VERSION = "0.3.0"
|
10
10
|
|
11
11
|
def main(argv)
|
12
|
-
|
13
|
-
STDERR.puts <<-EOS
|
14
|
-
Usage: sw windows_cmd_or_batch [options_for_the_cmd]
|
15
|
-
|
16
|
-
Internal Ruby command Usage:
|
17
|
-
#{File.basename(__FILE__)} env_out macro_out cwd_out windows_cmd_or_batch [options_for_the_cmd]
|
18
|
-
EOS
|
19
|
-
exit
|
20
|
-
end
|
12
|
+
options = parse_args!(argv)
|
21
13
|
|
22
14
|
unless [:cygwin, :msys, :wsl].include? UnixCompatEnv.compat_env
|
23
15
|
raise "You're in an unsupported UNIX compatible environment"
|
@@ -33,7 +25,9 @@ Internal Ruby command Usage:
|
|
33
25
|
win_cmd = concat_macrodump(win_cmd, macro_tmp_file_in)
|
34
26
|
win_cmd = concat_cwddump(win_cmd, cwd_tmp_file_in)
|
35
27
|
win_cmd += " & call exit %^SW_EXITSTATUS%"
|
36
|
-
|
28
|
+
if options[:show_cmd]
|
29
|
+
STDERR.puts "SW: " + win_cmd
|
30
|
+
end
|
37
31
|
Signal.trap(:INT, "SIG_IGN")
|
38
32
|
if UnixCompatEnv.compat_env == :wsl
|
39
33
|
# * Skip winpty, assuming the system's WSL supports ConPTY
|
@@ -60,8 +54,10 @@ Internal Ruby command Usage:
|
|
60
54
|
conv_setenv_stmts(env_tmp_file_in, argv[0], :bash, codepage)
|
61
55
|
conv_doskey_stmts(macro_tmp_file_in, argv[1], :bash, codepage)
|
62
56
|
gen_chdir_cmds(cwd_tmp_file_in, argv[2], :bash, codepage)
|
63
|
-
[
|
64
|
-
|
57
|
+
if !options[:preserve_dump]
|
58
|
+
[env_tmp_file_in, macro_tmp_file_in, cwd_tmp_file_in].each do |f|
|
59
|
+
File.delete f
|
60
|
+
end
|
65
61
|
end
|
66
62
|
rescue Errno::ENOENT
|
67
63
|
# ignore
|
@@ -72,6 +68,89 @@ Internal Ruby command Usage:
|
|
72
68
|
|
73
69
|
private
|
74
70
|
|
71
|
+
def parse_args!(argv)
|
72
|
+
options = {}
|
73
|
+
while argv.length > 0 && argv[0].start_with?("-")
|
74
|
+
arg = argv.shift
|
75
|
+
case arg
|
76
|
+
when "--"
|
77
|
+
next
|
78
|
+
when "--show-cmd"
|
79
|
+
options[:show_cmd] = true
|
80
|
+
when "--preserve-dump"
|
81
|
+
options[:preserve_dump] = true
|
82
|
+
when "--debug"
|
83
|
+
options[:show_cmd] = true
|
84
|
+
options[:preserve_dump] = true
|
85
|
+
when "--help", "-h"
|
86
|
+
puts help
|
87
|
+
exit
|
88
|
+
when "--version", "-v"
|
89
|
+
STDERR.puts "SourceWinBat Version #{VERSION}"
|
90
|
+
exit
|
91
|
+
else
|
92
|
+
STDERR.puts "Unknown option '#{arg}'"
|
93
|
+
exit 1
|
94
|
+
end
|
95
|
+
end
|
96
|
+
if argv.length < 4 || argv[3].chomp.empty?
|
97
|
+
STDERR.puts "Error: No Windows command is given\n---"
|
98
|
+
STDERR.puts help
|
99
|
+
exit 1
|
100
|
+
end
|
101
|
+
|
102
|
+
options
|
103
|
+
end
|
104
|
+
|
105
|
+
def help
|
106
|
+
<<EOS
|
107
|
+
sw, or SourceWinBat, is a utility to run Windows batch files from WSL /
|
108
|
+
MSYS2 / Cygwin and sync environment variables, and working directories
|
109
|
+
between batch files and their UNIX Bash shell.
|
110
|
+
|
111
|
+
Usage:
|
112
|
+
sw [ [sw_options] -- ] win_bat_file [args...]
|
113
|
+
|
114
|
+
Sw options:
|
115
|
+
-h --help Show this help message
|
116
|
+
-v --version Show the version information
|
117
|
+
--preserve-dump Preserve the environment dump files of cmd.exe for
|
118
|
+
debugging
|
119
|
+
--show-cmd Show the command executed in cmd.exe for debugging
|
120
|
+
--debug Enable '--preserve-dump' and '--show-cmd' options
|
121
|
+
|
122
|
+
Examples:
|
123
|
+
sw echo test
|
124
|
+
sw somebat.bat
|
125
|
+
|
126
|
+
You can control some behavior of SourceWinBat by defining following environment
|
127
|
+
variables.
|
128
|
+
|
129
|
+
Blacklisting and Whitelisting Environment Variable Not to be Synced:
|
130
|
+
|
131
|
+
SWB_BLACKLIST Define comma-separated environment variable names with
|
132
|
+
regular expressions. All environment variables included
|
133
|
+
in this list will not be synced by SourceWinBat.
|
134
|
+
|
135
|
+
SWB_WHITELIST Define variable names in the same manner as that of
|
136
|
+
SWB_BLACKLIST. All environment variables that are NOT
|
137
|
+
included in the list will NOT be synced by SourceWinBat.
|
138
|
+
|
139
|
+
Examples:
|
140
|
+
|
141
|
+
export SWB_BLACKLIST="foo:bar:baz_.*"
|
142
|
+
|
143
|
+
"foo", "bar", and any variables name of which start with "baz_" will not
|
144
|
+
be synced
|
145
|
+
|
146
|
+
export SWB_BLACKLIST="sync_taboo"
|
147
|
+
export SWB_WHITELIST="sync_.*"
|
148
|
+
|
149
|
+
Only variables name of which start with "sync_" will be synced,
|
150
|
+
except "sync_taboo".
|
151
|
+
EOS
|
152
|
+
end
|
153
|
+
|
75
154
|
def detect_ansi_codepage
|
76
155
|
if !STDOUT.isatty && UnixCompatEnv.compat_env == :wsl
|
77
156
|
# cmd.exe seems to use UTF-8 when Stdout is redirected in WSL. TODO: Is it always fixed?
|
@@ -254,7 +333,7 @@ Internal Ruby command Usage:
|
|
254
333
|
key, body = /([^=]*)=(.*)$/.match(doskey_stmt)[1..2]
|
255
334
|
|
256
335
|
is_key_valid = /^[a-zA-Z][0-9a-zA-Z]*$/ =~ key
|
257
|
-
|
336
|
+
next if !is_key_valid
|
258
337
|
|
259
338
|
body_substituted = escape_singlequote(body.chomp)
|
260
339
|
.gsub(/(?<param>\$[1-9]|\$\$|\$\*)/, '\'"\k<param>"\'')
|
data/source_win_bat.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'source_win_bat'
|
3
|
-
s.version = '0.
|
4
|
-
s.date = '2019-
|
3
|
+
s.version = '0.3.0'
|
4
|
+
s.date = '2019-02-06'
|
5
5
|
s.summary = "'source' Windows bat files in your UNIX compatible shell in Windows"
|
6
6
|
s.description = <<EOS
|
7
7
|
sw, or SourceWinBat, is a utility to run Windows batch files from WSL /
|
data/test/setcwd.cmd
CHANGED
data/test/test_ansicpchars.bash
CHANGED
@@ -16,7 +16,7 @@ sw echo %jp% > /dev/null # Re-import $jp from Windows
|
|
16
16
|
sw set jp2=あいうえお > /dev/null
|
17
17
|
[[ $(echo $jp2) = "あいうえお" ]]; tap_okif $?
|
18
18
|
|
19
|
-
|
19
|
+
cd $(to_unix_path "C:\\")
|
20
20
|
tmp="$(to_unix_path "$(sw echo %TEMP% | strip)")/sw_日本語ディレクトリ"
|
21
21
|
rm -rf "$tmp"
|
22
22
|
mkdir "$tmp"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: source_win_bat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takaya Saeki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: "sw, or SourceWinBat, is a utility to run Windows batch files from WSL
|
14
14
|
/\nMSYS2 / Cygwin and sync environment variables, doskeys, and working \ndirectories
|