335 questions
0
votes
1
answer
82
views
History navigation, autocomplete does not work in bash on Ubuntu24 WSL2 [closed]
I created a fresh WSL2 container of Ubuntu-24.04. Also, I created a new default user there that has different name than my Win user, moved the container file to another location. In general, the ...
4
votes
1
answer
110
views
How to create a custom command that has an argument that tab completes to a git branch in bash?
The first positional argument to git switch can be a branch, e.g. git switch <branch> and it tab completes nicely.
How can I make my own command with an argument that can tab complete into a ...
0
votes
1
answer
70
views
Match bash completions against one set of values, but insert a different associated value for each match value
How can bash completions match against one set of values, but insert a different associated value per match value?
e.g., I want to match against, and display, text names, but I want to insert a ...
0
votes
2
answers
130
views
Custom bash completion obtaining from help text
For some reason Bash completion doesn't work when I obtain from help text.
This is my C++ file compiled and placed as dbcmd executable file in one of the PATHs:
$ cat dbcmd.cpp
#include <iostream&...
1
vote
1
answer
189
views
zsh completion function (compdef) not completing _arguments
I am writing an autocomplete function for my personal cli. Here below is a reduced version of my compdef.
As I type my-cli <TAB> I can see the subcmd autocompleting.
As I type my-cli macos <...
0
votes
0
answers
59
views
bash complete to empty string while still escaping characters in file completions & appending / to dir completions
TL;DR
In bash (preferably bash 3+), how can I support empty string ('') as a completion (amongst others) for a value for an option for a command, while also supporting path completions for other ...
0
votes
0
answers
77
views
Is it possible to manually invoke a specific bash-completion function on the command line?
I have several scripts that expect a git branch as argument, rather than specifying the completion mechanism for all of these, is it possible to invoke a specific "completion activity" ...
-2
votes
1
answer
187
views
How to write an autocompletion function in bashrc for words from history?
How to write an autocompletion function in bashrc for previously used words (not commands in full) from history?
For example
less firstFile.txt
gvim secondFile.txt
Then suppose we want to ...
0
votes
1
answer
49
views
Bash completion for a program in a specific directory
If I have a program located in /a/prog and /a is not in PATH, is it possible to specify a bash completion for running ./prog in /a so that it doesn't affect any other program named prog located ...
0
votes
2
answers
75
views
How can I use bash auto-completion to list the contents of a directory literally named "="?
For example, using Tab to auto-complete, with a relative path:
user:~$ ls -la /foo
total 0
drwxr-xr-x 3 root root 60 Nov 9 22:31 .
drwxr-xr-x 1 root root 260 Nov 9 22:31 ..
drwxr-xr-x 5 root ...
2
votes
2
answers
329
views
How to include completions for one command in those of another
I have a command ts which takes as its arguments a command and that command's arguments. I want tab-completion to "do the right thing", namely:
When I type, for example ts foo<tab> ...
0
votes
0
answers
66
views
Bash completion and the $cur variable
I have some programs for which I've created some bash completion scripts, and those seem to work OK. I'd like to add some tests, and though this approach looked promising, but I get unexpected ...
1
vote
1
answer
142
views
Bash completion in wrapper scripts
I have a program foo for which I've written a bash-completion script, and that all works fine. I have dozens of wrapper-scripts bar1, bar2 ... which just sets one of the command-line options
#/usr/...
1
vote
1
answer
94
views
How to take full advantage of Git Bash completion for a passthrough command that takes its own args?
I have created a custom Git command called git-profile. It uses the git-<command> naming convention to enable use as compword in Git Bash completion. implemented as a Bash script, that accepts a ...
1
vote
1
answer
66
views
Git autocomplete custom command (not arguments after)
I've been trying to add an autocomplete for my custom command, "git extract-unmerged". I'm using git on Windows in git bash through MSYS2 if it matters.
I created a bash script in $HOME/...
0
votes
1
answer
272
views
set the group variable in azure devops pipeline using bash script
#!/bin/bash
# Read Docker Compose file
compose_file="docker-compose.yml"
images=($(grep -E '^ *image:' $compose_file | awk '{print $2}' | cut -d ':' -f 1))
# Initialize group variable
...
-4
votes
1
answer
77
views
Removing "\n" character while writing into a file in a shell script
Here I am taking the text input from the YAD UI field, and then I am writing that text into a file solc.c, but that text contains some \n characters, which are directly being written into file solc.c.
...
0
votes
0
answers
52
views
File compression and log rotation
I have a usecase to compress 5 days of log files and then delete 7 days data. My folder structure is as /user/var/logs/fw/2024-01.01/01.log.
At the moment I have a cron which is rotating the logs ...
1
vote
0
answers
212
views
bash autocomplete seemingly hangs
Consider the following very simple bash autocompletion specification.
#/usr/bin/env bash
_foo ()
{
local cur="${COMP_WORDS[$COMP_CWORD]}"
# The following line, when uncommented, ...
0
votes
1
answer
442
views
Enable SSH autocomplete for function which calls SSH
I created a simple function in .bashrc to ssh into a specific machine and enter a specific tmux session:
# Function to ssh to a machine with tmux
connect() {
local host=$1
local session=${2:-...
1
vote
1
answer
136
views
Bash command completion with custom function, regex on current completed word not working?
I'm writing a custom completion function for a bash script (this script is for activating deactivating nginx configuration files). I'm trying to have a different behavior if the completed word starts ...
0
votes
1
answer
231
views
How not to display tags in git autocompletion?
When using completion in git, for example on the git checkout command, all tags are returned.
I have more and more tags, which makes reading quite unpleasant.
user:~/repo$ git branch
prod
staging
...
0
votes
0
answers
226
views
Why does COMP_WORDBREAKS exists? What are usefull cases for using COMP_WORDBREAKS?
Many confused programmers stumbled upon COMP_WORDBREAKS. The documentation states https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html :
COMP_WORDBREAKS
The set of characters that ...
1
vote
1
answer
66
views
Trigger completion within GHCi when using :main
I'm using the optparse-applicative library, which supports Bash-completion. I'd like to trigger such completion when typing :main <tab> within GHCi. Is there a way to instruct GHCi to use the ...
1
vote
1
answer
601
views
How to activate bash-completion for cnpg's kubectl plugin when running on a local k3s node? [closed]
cnpg completion is designed to work when running like this:
. <( kubectl cnpg completion bash )
however, when running on a k3s node, the proper way to run kubectl is either:
k3s kubectl ...
or, ...
1
vote
0
answers
70
views
Run bash completion command for given command
I am trying to create a bash completion for a custom function that I am creating:
gco() {
if [ -z "$1" ]; then
branch="$(git branch --all | fzf | tr -d '[:space:]')"
...
2
votes
0
answers
1k
views
How to add bash auto completion to `k3s kubectl ...`?
I add bash-completion for k3s by running:
. <( k3s completion bash )
When I run the following, I only get bash-completion for kubectl ... and not k3s kubectl ...:
. <( k3s kubectl completion ...
0
votes
1
answer
136
views
Bash Completion how to ask it not to append a SPACE after current word is completed
In bash by default, pressing Tab will show all files and directories in the current directory. For example:
cat a<tab><tab> would display something like aFile.txt apples.png aDirectory/
If ...
1
vote
1
answer
85
views
bash completion for list of possible values of an environment variable
Consider an environment variable that can take a list of arbitrary possible meaningful values. For an example of such an environment variable consider AWS_PROFILE. The list of possible values can be ...
0
votes
1
answer
96
views
Bash completion with space key only if the line is empty
I have the following bash script
cmd_complete () {
make run
echo -n "${PS1@P}" # print prompt again
}
complete -F cmd_complete -E
bind "Space:complete"
This script does ...
0
votes
1
answer
809
views
How to hide private functions from the user in bash?
After sourcing the following code my terminal is able to see __hey function.
super_tools() {
case "$1" in
"hey")
__hey
;;
*)
...
3
votes
1
answer
300
views
How to make bash tab completion respect flags passed through git alias
If I type git switch --no-guess <TAB><TAB> I am presented with a list of local branches as possible completions. If I don't pass --no-guess then both local and remote branches are ...
1
vote
2
answers
3k
views
How can I get Bash and Zsh completions for VS Code on the commandline?
I would like to get Bash completions for code. How can that be done?
I tried using the search bar to see if this had already been asked (is:q [vscode] bash completion, is:q [vscode] [bash-completion], ...
2
votes
0
answers
133
views
pytest autocompletion in Bash
I am hoping to get Bash autocompletion to work with pytest. That is, suppose that I have a pytest file test_foo.py whose content is
def test_case_simple():
pass
then entering pytest test_foo.py:: ...
0
votes
1
answer
296
views
Bash completion not working after upgrading click version from version 7.0 to 8.1.3
Bash completion is working normally with Click 7.0
Environment:
Python version: 3.9.9
Click version: 7.0
Bash version: 5.1.8
Bash-completion:2.11
This is the code:
import click
@click.group(cls=...
0
votes
3
answers
113
views
Bash script string manipulation
So I have a array of file names, that contain some tar files,
So for example there are 2 file names in the array, acceptance-tests-0.0.134.tar and grafana-9.3.2-debian-11-r11.tar.
How to we write a ...
-1
votes
1
answer
44
views
Im trying to get users input in Bash
I need a command that can ask the user for input and do something with the resuld such as run if they answer with a specific result.
I tried
read -p
and i cant get input to work and i despretly need ...
0
votes
1
answer
253
views
How to write array elements to a file one per each line in shell? [duplicate]
I have an array in arr which contains list of strings - (string1 string2 string3 ...)
How do I append these elements to a text file one element per line.
The elements could be of any data type. But I ...
2
votes
3
answers
6k
views
How to detect OS system using BASH?
The script should be able to detect the operating system that is running.
The alternatives OS is Arch Linux, Centos and Ubuntu.
os=$(uname)
if [ "$os" == "Arch" ]; then
echo &...
-1
votes
2
answers
92
views
What's the meaning of “the initial non-assignment word on the line” in shell
In Programmable Completion Builtins complete command, there is a -I argument.
It said:
The -I option indicates that other supplied options and actions should apply to completion on the initial non-...
0
votes
0
answers
105
views
need help running chmod as part of a bash file. Documentation included [duplicate]
Ok so I want to write a bashfile system that tells a larger program that a file outputs this error message from chmod.
bash: ./\[bashfile-name\].sh: /bin/bash^M: bad interpreter: No such file or ...
1
vote
1
answer
407
views
Is there an autocomplete (__git_complete) for "git push origin"
trying to create git alias alias gpo = "git push origin" but there doesn't seem to be a __git_complete for git push with an origin, __git_complete gpo _git_push wants to autocomplete the ...
0
votes
1
answer
43
views
I'm trying to save the number received by executing the command to a file
The output to the terminal is correct, but it saves an empty line to the file.
echo -n "Enter secret: "
read secret
echo $(/opt/homebrew/bin/oathtool --totp -b $secret)
$(/opt/homebrew/bin/...
0
votes
1
answer
489
views
Bash-completion in makefile
I have a makefile. I want to ask for the name of the file that will be compiled in specific targets.
When I wrote make to the bash and press the tab it suggests the targets in makefile. However, it ...
0
votes
1
answer
386
views
Bash completion for git aliases containing multiple subcommands
I have set up the following alias in my .gitconfig file:
[alias]
ss = stash show
Unfortunately bash completion does not work correctly on this alias. When I type git ss <TAB>, I get:
❯ git ...
1
vote
1
answer
472
views
How can I invoke another program's bash completion handler for a single subcommand of my program?
Context
I have an arduino-cli wrapper script named ino that reads target/build configuration from:
JSON files located in the sketch directory
Command-line flags/arguments
It then constructs and exec'...
0
votes
0
answers
87
views
Git completion: no bash file names completion anymore
I added to ~/.config/bashrc this line:
. /usr/share/bash-completion/completions/git
Bash completion works, but I lost Bash files completion, is it expected? Is it possible to have both?
-1
votes
3
answers
485
views
Need to exclude and match regex in bash
i am new to bash and is trying to write a script that searches for some specific words in the codebase. But because there are a lot of false positives i also need to maintain a exclude_pattern list so ...
15
votes
4
answers
8k
views
How to complete rustup/cargo commands?
I have rustup+rust+cargo installed using the official installation script.
How do I enable shell completions, to be able to type cargo <TAB> in the terminal and see the possible commands such as ...
2
votes
1
answer
1k
views
Enable tab auto completion for kubectl in bash function
Given a bash function in .bashrc such as
kgp () {
kubectl get po -n $1 $2
}
Is it possible to have kubectl auto complete work for k8s resources such as namespaces/pods? As an example if I use
...