-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kopylov Vladislav
committed
Oct 25, 2024
1 parent
2e73f77
commit 496cb0d
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# How to add completion for a bash script | ||
|
||
|
||
1 - you have a script `dothis` | ||
|
||
```bash | ||
if [ -z "$1" ]; then | ||
echo "No command number passed" | ||
exit 2 | ||
fi | ||
|
||
exists=$(fc -l -1000 | grep ^$1 -- 2>/dev/null) | ||
|
||
if [ -n "$exists" ]; then | ||
fc -s -- "$1" | ||
else | ||
echo "Command with number $1 was not found in recent history" | ||
exit 2 | ||
fi | ||
``` | ||
|
||
2 - In order to write completion create a file `dothis-completion.bash` | ||
|
||
```bash | ||
#/usr/bin/env bash | ||
|
||
complete -W "now1 tomorrow1 never1" dothis | ||
``` | ||
|
||
3 - In order to add completion to your current bash session run | ||
|
||
```bash | ||
source ./dothis-completion.bash | ||
``` | ||
|
||
4 - Voilà! Now you can push <tab> and see complection | ||
|
||
[source](https://iridakos.com/programming/2018/03/01/bash-programmable-completion-tutorial) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters