Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
the initial commit of sash
  • Loading branch information
Eric Coan committed Feb 28, 2018
0 parents commit 781c3f3
Show file tree
Hide file tree
Showing 9 changed files with 488 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**Do you want to request a *feature* or report a *bug*?**

**What is the current behavior?**

**If the current behavior is a bug, please provide the steps to reproduce.**

**What is the expected behavior?**

**Which versions of SASH, and which OS are affected by this issue? Did this work in previous versions of SASH?**

20 changes: 20 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
*Before* submitting a pull request, please make sure the following is done...

1. Fork the repo and create your branch from `master`.
2. Read Contributing.MD
3. Added documentation where necessary.

Please use the simple form below as a guideline for describing your pull request.

Thanks for contributing to SASH!

-

**Summary**

[...]

**Test Plan**

[...]

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 1.0.0 (Feburary 28th, 2018)

- Initial Release of SASH.

20 changes: 20 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Contributing to SASH #
I want to make contributing to this project as easy and transparent as
possible.

## Pull Requests ##
I actively welcome your pull requests.

1. Fork the repo and create your branch from `master`.
2. Make sure your code works.
3. Make sure you update documentation where necessary.

## Issues ##

I use GitHub issues to track public bugs. Please ensure your description is
clear and has sufficient instructions to be able to reproduce the issue.

## License ##

By contributing to SASH, you agree that your contributions will be licensed
under its MIT license.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2018 Security Insanity

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
112 changes: 112 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# S.A.S.H. #

Sash is a series of bash v4 scripts built to help users modularize their bashrc.
If you're like me and have often wondered "why is this in my bashrc", or "oh shoot
where did I put this thing in my bashrc".

S.A.S.H. is built on the idea of "categories", and "sub-categories". "Categories"
being overarching categories such as "work"/"home"/"languages"/"utilties", where
sub-categories go within that such as "ruby" within "languages".

sash creates a directory structure under `~/.bash/plugins/`. Specifically:
`~/.bash/categories/<main_category>/<sub_category>/*.sh`. So although
sash will allow you to create those on your first run, you can make them
manually if you prefer.

## Installation ##

Installing sash for the first run is easy (the migration will take some time though).
Simply clone this repo:

```
$ git clone https://github.com/SecurityInsanity/sash
```

Then add the sash script to your .bashrc (this should be the only thing in there
ideally besides the boilerplate your os adds in):

```
$ echo "source ~/sash/sash.sh" >> ~/.bashrc
```

Then restart your terminal! It will ask you to create some initial overarching
categories if you didn't manually create them first.

## Usage ##

### sash_add ###

Whenever you need to add something to your modularized bashrc instead of manually
`mkdir && vim`'ing a file reach for `sash_add`:

```bash
ecoan@kappa:~$ . ~/.bash/sash-add.sh
ecoan@kappa:~$ sash_add
Please Choose a Category:
1) /home/CORP.INSTRUCTURE.COM/ecoan/.bash/plugins/utilities
2) /home/CORP.INSTRUCTURE.COM/ecoan/.bash/plugins/work
3) /home/CORP.INSTRUCTURE.COM/ecoan/.bash/plugins/language
#? 1
Please Choose a SubCategory:
1) New
#? 1
Please Enter the New Category Name: test
Please Enter a filename to add this content to (should end in .sh): test.sh
[+] Added, and sourced!
ecoan@kappa:~$ cat ~/.bash/plugins/utilities/test/test.sh
# This is a test of sash
# using multiline comments
export SASH_TEST=1
```

This will open two windows inbetween "subcategory", and "filename". One window for you
to type the content you want to add the bashrc, and one for you to type comments
(without the annoying '#' at the beginning of the line for long comments) so you can
know what it is when coming back to it later.

### sash_show ###

If you're like me you've probably created a lot of individual files under a specific subcategory.
To the point where you have so many files you don't want to manually cat them all out. Enter sash_show.
Sash show allows you to get a materialized view of an entire sub category so that way you know exactly what
content is in it.

```bash
ecoan@kappa:~$ sash_show
Please Choose a Category:
1) /home/CORP.INSTRUCTURE.COM/ecoan/.bash/plugins/utilities
2) /home/CORP.INSTRUCTURE.COM/ecoan/.bash/plugins/work
3) /home/CORP.INSTRUCTURE.COM/ecoan/.bash/plugins/language
#? 1
Please Choose a SubCategory:
1) ./test
#? 1

###############################################################
# Content from: /home/CORP.INSTRUCTURE.COM/ecoan/.bash/plugins/utilities/test/test.sh
###############################################################

# This is an example of
# adding some content to sash with multiple lines
# for testing
export SASH_TEST=1
ecoan@kappa:~$ sash_show utilities/test

###############################################################
# Content from: /home/CORP.INSTRUCTURE.COM/ecoan/.bash/plugins/utilities/test//test.sh
###############################################################

# This is an example of
# adding some content to sash with multiple lines
# for testing
export SASH_TEST=1
```


### sash_trace ###

If you aren't able to find out where a particular command is executing (or you want to see which
command is taking awhile to execute), you can set `SASH_TRACE=1` in your bashrc before the `source ~/sash/sash.sh`
line. This will turn sash in "debug mode" which prints out every command that is executed, and from which file it's
being execute from.

64 changes: 64 additions & 0 deletions sash-add.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

# Implements the sash_add/sash-add commands.
#
# S.A.S.H. is the main way to add things to your ~/.bashrc and still
# maintain structure.

# _sash_create_or_choose_subcategory(category: String) -> String
#
# Modifies Globals:
# - _sash_intermediate_choice
#
# allows the user to choose, or create a subcategroy within sash.
_sash_create_or_choose_subcategory() {
local category="$1"
local choice="$(cd "$category" && _sash_choose_a_directory "." 0)"
if [[ "$choice" == "New" ]]; then
read -p "Please Enter the New Category Name: " _sash_intermediate_choice
mkdir -p "$category/$_sash_intermediate_choice" > /dev/null 2>&1
echo "$_sash_intermediate_choice"
else
echo "$choice"
fi
}

# sash_add() -> None
#
# Modifies Globals:
# - _sash_add_filename
#
# allows the user to add content to their ~/.bashrc in a structured
# and sensible way.
sash_add() {
echo "Please Choose a Category: "
local category="$(_sash_choose_a_directory "$HOME/.bash/plugins/" 0)"
if [[ "$category" == "New" ]]; then
read -p "Please Enter the new Category Name: " _sash_add_filename
mkdir -p "$HOME/.bash/plugins/$_sash_add_filename"
category="$HOME/.bash/plugins/$_sash_add_filename"
fi
echo "Please Choose a SubCategory: "
local subcategory="$(_sash_create_or_choose_subcategory $category)"
subcategory="${subcategory#./}"
if ! _sash_get_multiline_input "# Please insert what you want to add to your bashrc below:\n"; then
exit 1
fi
local content_to_add="$sash_multiline_content"
if ! _sash_get_multiline_input "Please type what you want to be commented above this."; then
exit 1
fi
local content_to_comment="$sash_multiline_content"
read -p "Please Enter a filename to add this content to (should end in .sh): " _sash_add_filename
SAVEIFS=$IFS
IFS=$'\n'
content_to_comment=($content_to_comment)
IFS=$SAVEIFS
for (( i=0; i<${#content_to_comment[@]}; i++ )); do
echo "# ${content_to_comment[$i]}" >> "$category/$subcategory/$_sash_add_filename"
done
echo "$content_to_add" >> "$category/$subcategory/$_sash_add_filename"
source "$category/$subcategory/$_sash_add_filename"
echo "[+] Added, and sourced!"
}

55 changes: 55 additions & 0 deletions sash-show.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# sash-show.sh
#
# sash_show takes a category, and subcategory (either through args, or by
# letting the user choose) and prints out a "materialized view" of those files
# or them concatenated together with filenames.

# _sash_materialize_view(category: String, subcategory: String) -> String
#
# Modifies Globals: None
#
# Materializes a view for a category, and subcategory.
_sash_materialize_view() {
local category="$1"
local sub_category="${2#./}"

if [ ! -d "$category/$sub_category" ]; then
echo -e "${white}[${red}-${white}]${restore} Can't find category!"
echo "Cateogory is: [ $category/$sub_category ]."
return 1
fi

for filename in $category/$sub_category/*; do
echo ""
echo "###############################################################"
echo "# Content from: $filename"
echo "###############################################################"
echo ""
cat $filename
done
}

# sash_show(category: Option<String>, subcategory: Option<String>) -> String
sash_show() {
if [[ -n "$1" ]]; then
local full_category="$HOME/.bash/plugins/$1"
if [ ! -d "$full_category" ]; then
echo -e "${white}[${red}-${white}]${restore} Category doesn't exist!"
fi
if [[ -n "$2" ]]; then
_sash_materialize_view "$full_category" "$2"
else
echo "Please Choose a SubCategory:"
local choice="$(cd "$full_category" && _sash_choose_a_directory "." 1)"
_sash_materialize_view "$full_category" "$choice"
fi
return
fi
echo "Please Choose a Category:"
local category="$(_sash_choose_a_directory "$HOME/.bash/plugins/" 1)"
echo "Please Choose a SubCategory:"
local choice="$(cd "$category" && _sash_choose_a_directory "." 1)"
_sash_materialize_view "$category" "$choice"
}
Loading

0 comments on commit 781c3f3

Please sign in to comment.