Introduction
BashSupport Pro supports the source
command and follows sourced files.
Source Command Support
If you use the command with relative paths, then the plugin will automatically follow these files.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| ## a.bash
# Call 'Go To Declaration' on the filename to open it.
# BashSupport Pro uses declarations in lib.bash for:
# code completion
# - go to declaration
# - find usages
# - rename
# - quick documentation
source ./lib.bash
# Renaming 'myFunc' here
# also renames it in lib.bash
myFunc
|
1
2
3
4
5
6
7
| ## lib.bash, sourced by a.bash
# Renaming 'myFunc' here
# also renames it in a.bash
myFunc() {
echo hello world
}
|
Shellcheck Support
If you’re using dynamic values with the source
command, then BashSupport Pro needs help to locate the file.
For example, code like this is commonly used:
1
| . "${_basedir}/included-file.sh"
|
$_basedir
is only known at runtime and BashSupport Pro needs help here.
Define a shellcheck source directive to tell BashSupport Pro where to find the sourced file:
1
2
3
4
| # hint for BashSupport Pro where to find the file
# 'Go To Declaration' on the filename opens it
# shellcheck source=./lib/included-file.sh
. "${_basedir}/included-file.sh"
|
Now Go To
, Find Usages
, Rename
, etc. will also take care of the elements in the sourced file.
Go To Declaration
BashSupport Pro supports two scenarios:
- The declaration is in a sourced file
- The declaration is in a file, which sources the current file
1
2
| _base="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. ./included.sh
|
1
2
3
4
5
6
7
8
| # This file is sourced by main.sh
# It includes helper.sh on its own
. ./helper.sh
# "Go To Declaration" on the command
# navigates to "helper.sh"
printBasedir
|
1
2
3
4
5
6
7
| printBasedir() {
# "Go To Declaration"
# on $_basedir navigates to main.sh.
# This file is included by "included.sh",
# which is included by "main.sh"
echo $_base
}
|
Code Completion
Code completion works across multiple files.
Rename Refactoring
Rename
works across multiple files. Everything, which is located by Find Usages
is also renamed by this refactoring.