0

I have bash script kbase for 'cat' and 'grep -A10' from specified files for specific word with arguments. Main part of script.

cat ~/bash/kb/*.kb | grep "## $1" | grep $2 | grep $3

One .kb file is for example

## bash, folders, rename string in directory name
find -name "* *" -type d | rename 's/ /_/g'

## bash, files, remove all files instead *.jpg (or mp4)
find . -type f -not -name '*.jpg' -delete
rm -v !(*.jpg|*.mp4)

## bash, files, find files and multiple rename
find ./ -type f -readable -writable -exec sed -i "s/OLD/NEW/g" {} \;

First, I need grep whole content below until empty line, for example

kbase bash files rem

should display

## bash, files, remove all files instead *.jpg (or mp4)
find . -type f -not -name '*.jpg' -delete
rm -v !(*.jpg|*.mp4)

## bash, files, find files and multiple rename
find ./ -type f -readable -writable -exec sed -i "s/OLD/NEW/g" {} \;

Second, is possible to do it with autocompletion? For example when I will pressing TAB button, it shows me (grep) possibilities, for example

kbase ba<TAB><TAB>

should display

## bash, folders, rename string in directory name
## bash, files, remove all files instead *.jpg (or mp4)
## bash, files, find files and multiple rename

then continue typing

kbase bash fil<TAB><TAB>

should display

## bash, files, remove all files instead *.jpg (or mp4)
## bash, files, find files and multiple rename

then continue typing

kbase bash files rem<TAB><TAB>

should display final result (grep ## bash, files, rem ... until empty line in kb file)

## bash, files, remove all files instead *.jpg (or mp4)
find . -type f -not -name '*.jpg' -delete
rm -v !(*.jpg|*.mp4)

I tried many things but without success. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.