Skip to content

adamheins/s

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

s

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 the fact that these paths can be autocompleted with tab, allowing quick sourcing from anywhere. Completion scripts are provided for both bash and zsh.

Examples

ROS

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.

Installation

  1. Clone this repository:
    git clone https://github.com/adamheins/s ~/path/to/s
    
  2. Arrange for s.sh to be automatically sourced. For example, with bash this can be accomplished by adding the line source ~/path/to/s/s.sh to the ~/.bashrc file.
  3. Install completion script. When using bash, one just needs to source the script, such as by adding source ~/path/to/s/s_completion.bash to ~/.bashrc. When using zsh, one needs to add the _z script to the fpath; this can be accomplished by adding something like fpath=(~/path/to/s $fpath) to ~/.zshrc.
  4. Create the directory mkdir $S_DIR and add some scripts!

License

MIT

Releases

No releases published

Packages

No packages published

Languages