I'd would like a Make target to run for two prerequisite targets.
This example prints a once. I would like to print a twice for target foo.
a:
#echo 'hello from a'
foo: a bar
#echo 'hello from foo'
bar: a
#echo 'hello from bar'
make foo prints
hello from a
hello from bar
hello from foo
I would like make foo to print
hello from a
hello from a
hello from bar
hello from foo
Using GNU Make 3.81.
You could use a pattern rule to make separate "a" targets for foo and bar, like this:
a.%:
#echo 'hello from a'
foo: a.foo bar
#echo 'hello from foo'
bar: a.bar
#echo 'hello from bar
Related
I normally change part of the previous command using
!!:gs/Change/ChangeTo
To simplify I have created a function
funciton re() {
!!:gs/$1/$2
}
Now the output is like following
[~/Desktop]$ print -P '\033[34mThis is the same color as in your solarized palette\033[0m'
This is the same color as in your solarized palette
[~/Desktop]$ !!:gs/34/35
[~/Desktop]$ print -P '\033[35mThis is the same color as in your solarized palette\033[0m'
This is the same color as in your solarized palette
[~/Desktop]$ re 35 36
re:1: no such file or directory: !!:gs/35/36
[~/Desktop]✕127$
So, it is giving error re:1: no such file or directory: !!:gs/35/36 when I am invoking the function.
I have also tried
funciton re() {
^$1^$2^:G
}
It says command not found
[~/Desktop]$ re 35 36
^35^36^:G: command not found
[~/Desktop]✕127$
What might be the solution here?
You'll want to use the fc command. After a little experimentation:
re() { fc -e - "$1=$2"; }
Then:
$ echo foo bar
foo bar
$ re bar qux
echo foo qux
foo qux
I'm not sure how to suppress the edited command from being printed, if that's important for you.
Mr. glenn jackman,
I found that
re 2>/dev/null
suppresses all output.
I'd like to create a zsh-function that will put a computed string into the line editor, e.g.
insert_foo() {
# Do something that will put the string "foo" in the line editor
}
$ insert_foo
$ foo # <- "foo" appears in the line editor, without actually executing it
I know this is possible within a zle-widget, but can it also be it's own command?
We could use print -z:
insert_foo() {
print -z "foo"
}
Here is the zsh doc's copy for print -z:
print [ -abcDilmnNoOpPrsSz ] [ -u n ] [ -f format ] [ -C cols ]
...
-z Push the arguments onto the editing buffer stack, separated by spaces.
--- zshbuiltin(1), shell builtin commands, print
Given a text file, "hello.jl" in the current directory:
" Example hello world program."
function hello()
println("hello, world")
end
how would you display this to the Julia 1.0.0 REPL?
This is what I have so far:
julia> disp(f) = for line in readlines(open(f)); println(line); end
disp (generic function with 1 method)
julia> disp("hello.jl")
" Example hello world program."
function hello()
println("hello, world")
end
Is there a built-in command to do this in Julia?
You can use the run function and pass it a Cmd argument, in Linux, to run the cat system command.
Type semicolon ; in order to change to shell mode:
shell> cat hello.jl
"Example hello world program."
function hello()
println("hello, world")
end
Use the run function to execute a command outside of Julia:
julia> run(`cat hello.jl`) # Only works on Unix like systems.
"Example hello world program."
function hello()
println("hello, world")
end
Process(`cat hello.jl`, ProcessExited(0))
In Windows the type command should be analogous to Unix cat:
julia> show_file(path::AbstractString) = run(#static Sys.isunix() ? `cat $path` : `type $path`)
show_file (generic function with 1 method)
run returns the Process object:
julia> show_file("hello.jl")
"Example hello world program."
function hello()
println("hello, world")
end
Process(`cat hello.jl`, ProcessExited(0))
Use semicolon ; at the end of the line, to suppress the return output in the REPL:
julia> show_file("hello.jl");
"Example hello world program."
function hello()
println("hello, world")
end
Or you could just return nothing at the end of show_file if you like.
In the julia REPL, hit
;
to get to the REPL's built-in shell mode, then
shell> head path/to/my/filename
println(String(read("hello.jl")))
or
"hello.jl" |> read |> String |> println
I want to create a zsh completion for a tool with a virtual file tree.
e.g. my file tree looks like the following:
/
|- foo/
| |- bar
| |- baz/
| |- qux
|- foobar
My tool mycmd has a subcommand for listing the current directory:
$ mycmd ls
foo/
foobar
$ mycmd ls foo/
bar
baz/
My actual zsh completion looks like this:
_mycmd_ls() {
if [ ! -z "$words[-1]" ]; then
dir=$(dirname /$words[-1])
lastpart=$(basename $words[-1])
items=$(mycmd ls $dir | grep "^$lastpart")
else
items=$(mycmd ls)
fi
_values -s ' ' 'items' ${(uozf)items}
}
_mycmd() {
local -a commands
commands=(
'ls:list items in directory'
)
_arguments -C -s -S -n \
'(- 1 *)'{-v,--version}"[Show program\'s version number and exit]: :->full" \
'(- 1 *)'{-h,--help}'[Show help message and exit]: :->full' \
'1:cmd:->cmds' \
'*:: :->args' \
case "$state" in
(cmds)
_describe -t commands 'commands' commands
;;
(args)
_mycmd_ls
;;
(*)
;;
esac
}
_mycmd
IMHO is _values the wrong utility function. The actual behaviour is:
$ mycmd ls<TAB>
foo/ foobar
$ mycmd ls foo/<TAB> ## <- it inserts automatically a space before <TAB> and so $words[-1] = ""
foo/ foobar
I can't use the utility function _files or _path_files because the file tree is only virtual.
I would suggest to make use of compadd rather _values to get in control of the suffix character appended. Then looking at the available choices, set an empty suffix character in case a virtual directory is part of the result:
_mycmd_ls() {
if [ ! -z "$words[-1]" ]; then
dir=$(dirname /$words[-1])
lastpart=$(basename $words[-1])
items=$(mycmd ls $dir | grep "^$lastpart")
else
items=$(mycmd ls)
fi
local suffix=' ';
# do not append space to word completed if it is a directory (ends with /)
for val in $items; do
if [ "${val: -1:1}" = '/' ]; then
suffix=''
break
fi
done
compadd -S "$suffix" -a items
}
I have this function which works great in zsh, but I want to convert it to fish shell and I can't get it working.
function ogf () {
echo "Cloning, your editor will open when clone has completed..."
source <(TARGET_DIRECTORY=~/students EDITOR=$EDITOR clone_git_file -ts "$1")
}
First of all, since fish's syntax differs from zsh, you also have to change the output of clone_git_file to source it.
For example, if clone_git_file is something like:
#!/bin/bash
echo "FOO=$TARGET_DIRECTORY"
echo "BAR=$2"
you have to change it to fish syntax.
#!/bin/bash
echo "set -gx FOO $TARGET_DIRECTORY"
echo "set -gx BAR $2"
Now here's the ogf() function, and sample code for fish:
function ogf
echo "Cloning, your editor will open when clone has completed..."
source (env TARGET_DIRECTORY=~/students EDITOR=$EDITOR clone_git_file -ts $argv[1] | psub)
end
ogf MY_ARGUMENT
echo "FOO is $FOO"
echo "BAR is $BAR"
Running this code with fish, the output is:
FOO is /home/MY_USER/students
BAR is MY_ARGUMENT