Am I able to deactivate verbose output in the bash? - bash

I have aliases for many commands with their verbose flags, e.g.:
alias ninja='ninja --verbose -j 0'
Is there a mechanism in bash, where I can deactivate this flag afterwards?
I tried stuff like:
ninja --verbose=0
but that didn't work out.
I know that I can hide my output with /dev/null or that I can execute the binary directly with /path/to/ninja, but that's not the intent of my question. The answer might be command specific and depends on which mechanism for passing parameters the appropriate program uses, e.g. getopts. Anyways, I am looking forward to your help.
EDIT:
From comments I learned, that command ninja or escaping like nin\ja will ignore the complete alias, but not a specific parameter.

Related

Is there an option to describe a command and list its possible options in bash?

Is there an option to describe a command and list its possible options in bash/zsh? I tried looking for one and I could only find -h but it does not work for me and gives me the error bad option: -h on zsh and -h: invalid option in bash. Same for -?.
There is a separate command man. Most commands, certainly all the traditional commands, have a man page. Try man man.
The GNU coding standards state, that:
The standard --help option should output brief documentation for how to invoke the program, on standard output, then exit successfully. Other options and arguments should be ignored once this is seen, and the program should not perform its normal function.
So, for GNU programs, --help should provide you with the requested output (should, not will).
And for the rest: it is just wild west. Some implement -h for help. And others just believe that Google is the source for documentation.

How to view commands that `make` executes?

I have a Makefile, which fails at some point, with a git error. How can I view the git command that causes the whole make process to fail? More precisely, I am looking for a list of commands (including the ones that start with #) that I can run on an identical setup, to achieve the same effect as what make does.
I know for a script, instead of #! /bin/bash you would add a flag -x to it, and that would display all the commands before their execution. How do I do the same thing for make?
I am looking for a list of commands (including the ones that start with #) that I can run on an identical setup, to achieve the same effect as what make does.
By default, make echoes all recipe commands it runs, except those prefixed with #. The POSIX specifications for make do not describe a way to override that effect of # (but see below). It is conceivable that your make has an extension for that, but the make implementations you are most likely to be using (GNU make or BSD make, since you seem to assume that your standard shell is bash) do not.
Additionally, in POSIX-conforming make implementations, including the two mentioned above, the special target .SILENT can be used to suppress echoing the commands of some or all targets, and the -s command-line option can be used to suppress echoing for all targets.
You can print recipe commands prefixed with # if you run make with the -n (no-op) flag. That will print the commands for out-of-date targets without running them, except that those prefixed with a + are run even in no-op mode. Commands prefixed with # are included among those printed. Under some circumstances, the fact that most commands are not actually run in this mode can affect the output, but all the cases I can think of at the moment involve recursive make, and I think they are fairly unlikely.
POSIX seems to indicate that -n does not override -s or .SILENT, so if you have to deal with those then you may have no alternative but to modify your makefile. If you happen to be using GNU make, however, you will find that -n does override .SILENT and -s in that implementation. The same may be true of other makes.

Override bash completion for every command

I have a (possibly ill-advised) idea for improving tab completion based on the command history. Ideally, I'd want to apply this to every command in the terminal.
Basically I'm looking for something like:
complete -F _my_function *
where the glob actually works.
Is this at all possible, or would I have to set it manually for every command I use?
complete -D defines the "default" completion procedure, for all commands for which no specific completion has been set. If you want the default to apply to all commands, just don't set any specific completions. If you want to remove a completion, use complete -r command (or complete -r to erase all of them).
Also see complete -E.
For details, see the Bash manual.

Custom Bash Autocomplete with File Path Completion

I'm working on bash auto-completion for a project I'm the maintainer of. You can find the script here. I've cobbled this together with some hacking on my own, and with the help of some contributors who understand that completion APIs better than I do.
What we have works great -- with one exception. We can manage a completion like like this
//type
pestle.phar som[TAB]
//completes to
pestle.phar some-command-name
However, once we're here we lose file path/name completion that's a part of the stock bash shell. That is, working off the previous example, if a user types
//type
pestle.phar some-command-name /va[TAB]
we'd like it to complete to
//completes to the following, because var exists
pestle.phar some-command-name /var
Is there a way to just tell the complete command something like
Hey, in addition to everything we're telling you to do with our custom bash function, also keep your normal file path completion
If not, is there there some known science/boilerplate to reimplementing the file path completion in your own custom base completion functions?
Some other answers and the docs seem to indicate that the -o filenames or -o bashdefault options should take care of this -- but it doesn't seem to be working on OS X 10.11. I'm not sure if I misunderstand -o, or if the code in my completion files somehow overrides the -o behavior, or if OS X is doing it's I'm only a mostly well behaved unix thing.
Also -- if it's not obvious -- this is my first deep bash completion rodeo. If I've said something seemingly dumb/naive above please let me know. I may be looking for a fish right now, but I'd like to learn to fish in the bash completion river myself.
I think -o default (without -o filenames) should work for you. According to the manual:
bashdefault
Perform the rest of the default bash completions if the compspec generates no matches.
default
Use readline's default filename completion if the compspec generates no matches.
filenames
Tell readline that the compspec generates filenames, so it can perform any filename-specific processing (like adding a slash to directory
names, quoting special characters, or suppressing trailing spaces). Intended to be used with shell functions.
(Also see 'complete -d -o default cd' issue for the difference between -o default and -o bashdefault.)

User friendly command line options

I know boost::program_options from c++ which enables me to write user- friendly command-line options in almost no time. With "user- friendly" I mean, short and long options and a descriptive help command which would look similar to this:
Copy standard input to each FILE, and also to standard output.
-a, --append append to the given FILEs, do not overwrite
-i, --ignore-interrupts ignore interrupt signals
--help display this help and exit
--version output version information and exit
For myself I had to find out that this is really awkward in bash with the built-in getopts only supporting short options. Is this correct or am I wrong?
How would you implement user friendly command line options? If you know any links, best practices or in depths tutorials I would be really much appreciated.
GNU getopt supports long options and can be used from any Bourne-like or csh-like shell. ksh93's builtin getopts supports long options as well. zsh has a zparseopts.
There's a POSIX shell implementation of getopts (as a shell function) that supports long options at http://stchaz.free.fr/getopts_long.sh
Thank you for pointing me to the correct sources of information.
I decided to do it this way https://github.com/Mythli/tech/blob/master/bash/getopt.sh
The code is pretty straightforward so no explanation should be needed.

Resources