I want to run rust code with a keybinding such as .
I tried the command :!cargo run --bin %.
But in that case the % equals to 'src/bin/test.rs', instead of the wanted filename without suffix(which is test).
So how could I edit the command to cater to my needs?
As you can read in the vim help on filename-modifiers you can get the file name without path & extension by appending :t:r to the % register
so
:!cargo run --bin %:t:r
will run the binary of the current file for single file binaries.
If you need the last directory name (multi file binaries) you can use
:!cargo run --bin %:h:t
Related
I always have this doubt and I don't know why the file inside the bin folder which create a simple http server doesn't have a .js extension.
Is there a reason behind this?
It's tradition on unix that executables don't have extension.
For example, on Linux and MacOS to list a directory you type:
ls
you don't type
ls.exe
Another example, to launch the Dropbox service on Linux you can type
dropbox
you don't type
dropbox.py
even though dropbox is just a text file containing Python code.
Unix (and also bash terminal on Windows) have a feature where if a file is marked as executable (using the chmod command) and the first line contains:
#!
.. then the shell (the program controlling the command line) will remove the first two characters (#!) and execute the rest of that first line. This is often called the shbang line (sh = shell, ! = bang).
Therefore, if you want to develop a command-line program in node.js all you need to do is start the file with #! /usr/bin/env node:
#! /usr/bin/env node
// ^
// |
// the 'env' command will find the correct install path of node
console.log('hello world');
Then use chmod to make the file executable:
chmod +x my-script.js
Of course, creating a program that ends in .js does not look "professional". For example you don't type gulp.js when you run gulp and you don't type npm.js when you run npm. So people follow tradition and make their executable scripts have no extension - it makes it harder for people to realise that you didn't write the program in C or assembly language.
Because www file is executable.
Open a console, go to the bin folder, and type ./www . The server will run.
Trying to use the 'make' command in linux to compile c programs for class. If I do make it works, but if I type 'make' and then start typing the file name and tab it doesn't autocomplete the file for me. It's kind of annoying and I'd like to be able to use it instead of typing gcc -o everytime to test my program. How can I fix this?
edit
I have GalliumOS - 2.0 (ubuntu 16.04) fully installed on a c720 chromebook (ChromeOS has been completely removed and replaced with this)
The shell is bash.
edit2
adding the line complete -f -X '!*' make in my ~/.bashrc file works, but now I need help making it ignore directories or make it so that only .c and compiled c programs are added to the autocomplete.
It probably does not complete, because the parameter following make is usually the name of the target (for the recipe) and not a filename.
It perhaps completes for options that expect a filename, like e.g. make -f mymakefile.
I am using a tool called Droidbox for experiment.
The tool has a shell script droidbox.sh which I can invoke through terminal.
droidbox.sh takes one argument i.e path of the apk
Usage: ./droidbox.sh APK
I want to call the droidbox.sh through a shell script.
I wrote a shell script like
#!/bin/bash
ARG1="/home/xxx/a.apk"
/home/xxx/DroidBox_4.1.1/droidbox.sh "$ARG1"
I am getting error which says
python: can't open file 'scripts/droidbox.py': [Errno 2] No such file or directory
Can anybody point out what am I doing wrong?
Your error message does not come from your script, but from the called one.
It sounds like the droidbox.sh script is not very smart and requires you to set the current working directory before you can call it.
I would typically use also some more variables, so you better see what belongs together:
#!/bin/sh
set -e
BASEDIR="/home/xxx"
DROIDDIR="$BASEDIR/DrroidBox_4.1.1"
APKFILE="$BASEDIR/a.apk"
cd "$DROIDDIR"
"$DROIDDIR/droidbox.sh" "$APKFILE"
If you dont use set -e you better combine commands which need to succeed together:
cd "$DROIDDIR" && "$DROIDDIR/droidbox.sh" "$APKFILE"
Otherwise the cd might fail when the directory is missing and all following commands execute in the wrong directory.
This error is because you're running the script in a different folder than the folder that houses your "scripts/droidbox.py" file. You can fix this in the following way(s):
Move the "scripts/" folder to the directory that you're running this script out of using "mv /path/to/scripts/ ."
Move your customer script to the folder that contains scripts/droidbox.py and run the script from there
I am developing a php application using ViM. Is there a shortcut for me to run the currentEditing.php? Alternatively, is there a shortcut for running main.php?
It depends on your platform, certainly, but when I'm developing python I often run the current script just by executing :!%. The colon for a command (obviously), the bang for shell execute, and the percent for the current filename.
You can execute shell commands in ViM using the following syntax:
:!command -options arguments
Therefore, you need to save your file first, and then run whatever command you need for executing php.
I don't know php, so let me give you an example with compiling a C file:
... editing text
:w main.c # save to file
:!gcc -Wall main.c # compile the code
:!./a.out # execute the executable
Note that :! commands are run by shell and ViM has no understanding of it. Therefore, you can execute any command. This also means that the command cannot run on a modified, unsaved buffer.
I want to run a command in SCons which doesn't have any input/output files (actually the input and output are the same file). At the moment I am just manually running it with subprocess.Popen but is there a more SConsy way of doing it?
You can use the Command function to run whatever external command you run via Popen, and you can use the AlwaysBuild function to ensure your command is always run even if the target file exists. Scons doesn't like dependency cycles, so leave the source list empty.
myfile = env.Command('myfile.out', [], 'echo Hello world > $TARGETS')
env.AlwaysBuild(myfile)
The scons wiki also has a recipe for PhonyTargets which makes it easy to set up a lot of simple commands.