Read Ninja build file from command line - ninja

Is it possible to read a Ninja build file from STDIN, even without a build.ninja or other file present?

Yes, use /dev/stdin as the filename. Note that this probably won't work on Windows.
echo "# ninja!" | ninja -f /dev/stdin

Related

Alias ​to open a file by name

Aliases allow you to open certain file formats simply by typing the filename in a terminal. For example, if the file is of type html, htm, it will open in firefox. alias -s {html,htm}=firefox
I could do the same for text files and just list the types I want, but what if the file doesn't have them, like ~/.zshrc or /etc/fstab? How can I open such a file by name?
This function should do what you want (add it to .zshrc):
command_not_found_handler() {
if [[ -o interactive && -w $1 ]]; then
vi $1
else
echo zsh command_not_found_handler: command not found: $# >&2
return 1
fi
}
As the name indicates, this is called whenever zsh is unable to find a command entered in the shell. Now, if a 'command' isn't found, the editor will be invoked on that argument.
The -o interactive test should ensure that the editor is only called when you've typed something in; an invalid command in a shell script will still fail. The -w test checks for editable files.
You may find other conditions to check as you use this.
ETA: As noted in the comments, this only works with simple file names; it will not work if the path to the file is specified.
For common files you edit frequently you can make individual aliases for those files. I have aliases for
alias hosts="sudo vi /etc/hosts"
alias zshrc="vi ~/.zshrc"

How to specify wildcards in .qrc resource file of QML?

There are x number of .png files in a directory.
Instead of adding all these manually I would want to specify the directory path in the .qrc file and let it include all of them on its own.
What is the way to achieve this?
Here is a little bash script that generate a qrc file from the content of a folder
#!/bin/sh
QRC=./resourcefilename.qrc
echo '<!DOCTYPE RCC>' > $QRC
echo '<RCC version="1.0">' >> $QRC
echo ' <qresource>' >> $QRC
# for each files/folder in the folder "theFokderName"
for a in $(find theFolderName -d)
do
# if this is not a folder
if [ ! -d "$a" ]; then
echo ' <file>'$a'</file>' >> $QRC
fi
done
echo ' </qresource>' >> $QRC
echo '</RCC>' >> $QRC
You can easily customize it.
No, this is not yet possible, see this bugreport for details.
Just for documentation, I found a workaround to this on this link.
The following entry in project.pro ensures that the resources are built into the application binary, making them available when needed:
RESOURCES += \
qml/main.qml \
images/image1.png \
images/image2.png
A more convenient approach is to use the wildcard syntax to select several files at once:
RESOURCES += \
$$files(qml/ *.qml) \
$$files(images/ *.png)
So, if you use $$file(wildcard) on your .pro file, it would work. I tried and it worked OK.
If you’re using qmake you can simply reference the folder containing your assets like this in your project file:
RESOURCES += images/
No need to use scripts or even the $$files() helper, unless you want to glob by file extension.

Editing/Replacing content in multiple files in Unix AIX without opening it

I have multiple files in Unix directory.
files names are as below.
EnvName.Fullbkp.schema_121212_1212_Part1.expd
EnvName.Fullbkp.schema_121212_1212_Part2.expd
EnvName.Fullbkp.schema_121212_1212_Part3.expd
In each of the above file there is a common line like below. eg
EnvName.Fullbkp.schema_121212_1212_Part1.expd
is having below data
Log=EnvName.Fullbkp.schema_10022012_0630_Part1.log
file=EnvName.Fullbkp.schema_10022012_0630_Part1.lst
EnvName.Fullbkp.schema_121212_1212_Part2.expd
is having below data
Log=EnvName.Fullbkp.schema_10022012_0630_Part2.log
file=EnvName.Fullbkp.schema_10022012_0630_Part2.lst
I want to replace the 10022012_0630 from EnvName.Fullbkp.schema_121212_1212_Part*.expd files with 22052013_1000 without actully opening those files. Changes should happen in all EnvName.Fullbkp.schema_121212_1212_Part*.expdp files in a directory at a time
Assuming you mean you don't want to manually open the files:
sed -i 's/10022012_0630/22052013_1000/' filename*.log
update: since the "-i" switch is not available on AIX, but assuming you have ksh (or a compatible shell):
mkdir modified
for file in filename*.log; do
sed 's/10022012_0630/22052013_1000/' "$file" > modified/"$file"
done
Now the modified files will be in the modified directory.
It's some kind of extreme optimist who suggests sed -i on AIX.
It's a bit more likely that perl will be installed.
perl -pi -e 's/10022012_0630/22052013_1000/' EnvName.Fullbkp.schema_121212_1212_Part*.expd
If no perl, then you'll just have to do it like a Real Man:
for i in EnvName.Fullbkp.schema_121212_1212_Part*.expd
do
ed -s "$i" <<'__EOF'
1,$s/10022012_0630/22052013_1000/g
wq
__EOF
done
Have some backups ready before trying these.

replacing dos2unix line endings

I am using the following code to replace dos2unix line endings. Every time I execute the code it gets stuck at the command prompt. What is wrong with the below command?
for i in `find . -type f \( -name "*.c" -o -name "*.h" \)`; do sed -i 's/\r//' $i ; done
In Ubuntu, dos2unix and unix2dos are implemented as todos and frodos respectively. They are available in the package tofrodos.
I suggest using
find . -type f \( -name "*.c" -o -name "*.h" \) -print0 | xargs -0 frodos
I suggest confirming that your find command and for loop work properly.
You can do this by simply using an echo statement to print each file's name.
Depending on your platform (and how many .c and .h files you have) you might need to use xargs instead of directly manipulating the output from find. It's hard to say, because you still haven't told us which platform you're on.
Also, depending on your platform, different versions of sed work differently with the -i option.
Sometimes you MUST specify a file extension to use for the backup file, sometimes you don't have to.
All of the above are reasons that I suggest testing your command piece by piece.
You should read the man pages for each command you're trying to use on the system on which you're trying to use it.
Regarding the sed portion of your command, you should test that on a single file to make sure it works.
You can use the following sed command to fix your newlines:
sed 's/^M$//' input.txt > output.txt
You can type the ^M by typing CTRLv CTRLm
Like I said before, the -i option works differently on different platforms.
If you have trouble getting that to work, you could have sed output a new file and then overwrite the original file afterwards.
This would be very simple to do inside your for loop.

Is it possible to create a symlink to the latest file in a directory?

I have a home directory in my unix box. I would like to setup a number or shortcuts in it to point to the latest file in another directory and the link will update if a newer file is created.
Is this possible?
So far I able to get the latest file:
ls -lrt | tail -n1
Thanks
[EDIT]
Perhaps I could even create a shell instead of a softlink which finds the latest file and returns it so I can open/grep/delete etc?
In bash, this will make a link to the latest file or directory in "target-directory" called "latest":
ln -s target-directory/`ls -rt target-directory | tail -n1` latest
And this will wait for a change in "target-directory" before returning:
inotifywait -e attrib target-directory

Resources