A simple tool for easily sourcing shell scripts. Scripts are located in the
$S_DIR directory, defined in s.sh as ~/.s. Scripts placed under $S_DIR
(including in subdirectories) can be sourced by simply typing
> s path/to/script.sh
where the script is located at $S_DIR/path/to/script.sh. The real convenience
of this tool is that these paths can be auto-completed by pressing tab,
allowing quick sourcing from anywhere. Completion scripts are provided for both
bash and zsh.
It's kind of annoying to navigate to the root of a Python project and type
source .venv/bin/activate whenever I want to enter its virtual environment.
If copied to $S_DIR, the script examples/venv.sh allows one to source the
virtual environment from anywhere in the project directory tree by simply
running s venv.sh (which can be conveniently tab-completed).
Suppose I have different robots or machines I want to communicate with (at
different times) using the Robot Operating System
(ROS). To do so, I need to change the $ROS_IP and
$ROS_MASTER_URI environment variables. I certainly don't want to type out the
required IP addresses each time (and in each different shell window I may be
using!). Simply create a script $S_DIR/ros/myrobot.sh with something like
export ROS_IP=<my IP address>
export ROS_MASTER_URI=http://<ROS master IP address>:11311
# echo the results
echo ROS_MASTER_URI=$ROS_MASTER_URI
echo ROS_IP=$ROS_IP
To switch back to using your local computer as the ROS master, use the script
$S_DIR/ros/local.sh containing
export ROS_MASTER_URI=http://localhost:11311
unset ROS_IP
unset ROS_HOSTNAME
echo ROS_MASTER_URI=$ROS_MASTER_URI
echo Unset ROS_IP and ROS_HOSTNAME
Now you can easily switch ROS configurations:
> s ros/myrobot.sh
...
> s ros/local.sh
...
The ros/local.sh script as well as another called ros/devel.bash, which
automatically sources the devel/setup.bash script from anywhere in the catkin
workspace, are included in the examples directory.
- Clone this repository:
git clone https://github.com/adamheins/s ~/path/to/s - Arrange for
s.shto be automatically sourced. For example, with bash this can be accomplished by adding the linesource ~/path/to/s/s.shto the~/.bashrcfile. - Install completion script. When using bash, one just needs to source the
script, such as by adding
source ~/path/to/s/s_completion.bashto~/.bashrc. When using zsh, one needs to add the_zscript to thefpath; this can be accomplished by adding something likefpath=(~/path/to/s $fpath)to~/.zshrc. - Create the directory
mkdir $S_DIRand add some scripts!
MIT