Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
redox-os
ion
Commits
ca069ed1
Commit
ca069ed1
authored
May 01, 2020
by
Xavier L'Heureux
Committed by
AdminXVII
May 02, 2020
Browse files
If the source-sh argument is a file, execute it instead of a literal script
parent
e92269fb
Changes
3
Hide whitespace changes
Inline
Side-by-side
.envrc
View file @
ca069ed1
eval "$(lorri direnv)"
\ No newline at end of file
use_nix
src/binary/mod.rs
View file @
ca069ed1
...
...
@@ -434,5 +434,6 @@ where
fn
word_divide
(
buf
:
&
Buffer
)
->
Vec
<
(
usize
,
usize
)
>
{
// -> impl Iterator<Item = (usize, usize)> + 'a
WordDivide
{
iter
:
buf
.chars
()
.copied
()
.enumerate
(),
count
:
0
,
word_start
:
None
}
.collect
()
// TODO: return iterator directly :D
WordDivide
{
iter
:
buf
.chars
()
.copied
()
.enumerate
(),
count
:
0
,
word_start
:
None
}
.collect
()
// TODO: return iterator directly :D
}
src/lib/builtins/mod.rs
View file @
ca069ed1
...
...
@@ -260,17 +260,21 @@ SYNOPSYS
source-sh SCRIPT
DESCRIPTION
Execute the script literal given in argument and apply env vars diff to the current shell"
Execute the script given in argument and apply env vars diff to the current shell
If the script is a file, the file is executed, else is it treated as a literal script"
)]
pub
fn
source_sh
(
args
:
&
[
types
::
Str
],
_shell
:
&
mut
Shell
<
'_
>
)
->
Status
{
let
arg
=
match
args
.get
(
1
)
{
let
mut
arg
=
match
args
.get
(
1
)
{
None
=>
return
Status
::
bad_argument
(
"Please pass a shell script as option"
),
Some
(
arg
)
=>
arg
,
Some
(
arg
)
=>
Cow
::
Borrowed
(
arg
)
,
};
let
temp
=
match
Temp
::
new_file
()
{
Ok
(
f
)
=>
f
,
Err
(
e
)
=>
return
Status
::
error
(
format!
(
"Could not create temp file for source-sh: {}"
,
e
)),
};
if
let
Ok
(
s
)
=
std
::
fs
::
read_to_string
(
arg
.as_str
())
{
arg
=
Cow
::
Owned
(
s
.into
());
}
let
script
=
format!
(
"{}
\n
env | sort > {}"
,
arg
,
temp
.as_path
()
.display
());
match
Command
::
new
(
"sh"
)
.args
(
&
[
"-c"
,
&
script
])
...
...
@@ -296,14 +300,13 @@ pub fn source_sh(args: &[types::Str], _shell: &mut Shell<'_>) -> Status {
let
val
=
match
iter
.next
()
{
Some
(
v
)
=>
v
,
None
=>
{
return
Status
::
error
(
format!
(
"Could not parse env file, no value for: '{}'"
,
name
))
eprintln!
(
"Invalid environment variable '{}'. Proceeding anyway"
,
name
);
continue
;
}
};
let
prev_val
=
std
::
env
::
var_os
(
name
);
if
prev_val
.as_ref
()
.and_then
(|
x
|
x
.to_str
())
!=
Some
(
val
)
{
println!
(
"Set {} to {}"
,
name
,
val
);
std
::
env
::
set_var
(
name
,
val
);
}
}
...
...
ahkrr
@ahkrr
mentioned in issue
#942
·
May 30, 2020
mentioned in issue
#942
mentioned in issue #942
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment