Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refined setup #14

Merged
merged 9 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 57 additions & 26 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# ⚡️ WIX CLI ⚡️

Optimize your development productivity in the terminal

<hr>

[![CODEQL](https://github.com/hwixley/wix-cli/actions/workflows/github-code-scanning/codeql/badge.svg)](https://hwixley.github.io/wix-cli/) [![GITHUB_PAGES](https://github.com/hwixley/wix-cli/actions/workflows/pages/pages-build-deployment/badge.svg)](https://hwixley.github.io/wix-cli/) ![License](https://img.shields.io/badge/License-MIT-purple?labelColor=gray&style=flat) ![Version](https://img.shields.io/badge/Version-1.0.0-blue?labelColor=gray&style=flat) ![Platforms](https://img.shields.io/badge/Platforms-BASH%20&%20ZSH-orange?labelColor=gray&style=flat)

<hr>

![wix-terminal](https://user-images.githubusercontent.com/57837950/233463510-d7bf606c-d0a9-45d6-902f-ce0df53862a7.png)
Expand All @@ -21,7 +23,7 @@ Optimize your development productivity in the terminal
- [Extra Feature Setup](#extra-feature-setup)
- [Factory-reset Installation](#factory-reset-installation)
- [List of Commands](#list-of-commands)
- [Defaults](#defaults)
- [Defaults](#defaults)
- [Navigation](#navigation)
- [Pseudo-random String Generation](#pseudo-random-string-generation)
- [Code Editing](#code-editing)
Expand All @@ -31,7 +33,9 @@ Optimize your development productivity in the terminal
- [Data for Custom Scripting Logic](#data-for-custom-scripting-logic)
- [Editing Data for Custom Scripting Logic](#editing-data-for-custom-scripting-logic)
- [File Utilities](#file-utilities)
- [Other Utilities](#other-utilities)
- [Network Utilities](#network-utilities)
- [Image Utilities](#image-utilities)
- [Text Utilities](#text-utilities)
- [Bugs, New Features, \& Questions](#bugs-new-features--questions)
- [Make A Contribution](#make-a-contribution)
- [Support This Project](#support-this-project)
Expand All @@ -53,7 +57,8 @@ I knew I was not the only one who had suffered from these productivity issues as
## Dependencies

<ins>The dependencies include:</ins>
- `openssl` for the [Pseudo-random String Generation](https://github.com/hwixley/wix-cli#pseudo-random-string-generation) commands.

- `openssl` for the [Pseudo-random String Generation](https://github.com/hwixley/wix-cli#text-utilities) commands.
- `git` for all [Git Automation](https://github.com/hwixley/wix-cli#git-automation) commands.
- Visual Studio Code for the `vsc` code editor command.
- XCode for the `xc` code editor command (only available for Macintosh systems).
Expand All @@ -63,46 +68,56 @@ I knew I was not the only one who had suffered from these productivity issues as

## Installation

1. Clone this repository into a folder of your choice:
1. Clone this repository into a folder of your choice:

```
git clone git@github.com:hwixley/WIX-CLI.git
```

2. Navigate into the directory:

```
cd WIX-CLI
```

3. Give permissions to the setup script and run it:

```
chmod +x setup.sh && ./setup.sh
```

4. Reopen your terminal or run `source ~/.bashrc` (`source ~/.zshrc` for unix systems)

Type `wix` to see the list of commands and start developing some magic!

## Extra Feature Setup

1. You can use OpenAI's ChatGPT to write commit messages for you (using `git diff` and `git status` outputs) when using the `wix push` command. <i>This requires an OpenAI API key.</i>

```
wix setup smart_commit
```

## Factory-reset Installation

1. Remove your installation

```
rm -rf <path-of-installation>
```

1. Remove the wix-cli script setup in your environment file
- Open the file in an editor: (`~/.bashrc` for linux systems, and `~/.zshrc` for unix systems)
```
gedit ~/.bashrc
```
If `gedit` is not available you can always use vim instead:
```
vi ~/.bashrc
```
- Remove the 2 lines for the wix-cli:<br>
- The first line is a comment: `# WIX-CLI`<br>
- The second line is where the command is actually setup: `alias wix="<path-of-installation>/wix-cli.sh"`
- Open the file in an editor: (`~/.bashrc` for linux systems, and `~/.zshrc` for unix systems)
```
gedit ~/.bashrc
```
If `gedit` is not available you can always use vim instead:
```
vi ~/.bashrc
```
- Remove the 2 lines for the wix-cli:<br>
- The first line is a comment: `# WIX-CLI`<br>
- The second line is where the command is actually setup: `alias wix="<path-of-installation>/wix-cli.sh"`
2. Follow the [installation instructions](https://github.com/hwixley/wix-cli#installation)

<hr>
Expand All @@ -112,6 +127,7 @@ rm -rf <path-of-installation>
Please note any command with an argument in angle brackets below (ie. `<branch>`) denotes a dynamic variable which is given by the user. If the text inside these angle has a `?` character at the end (ie. `<branch?>`) this denotes that this argument is optional and if left empty will fallback to the default.

#### Defaults

- `<branch?>` : if left empty the current branch will be used
- `<org?>` : if left empty the default GitHub organisation set in `myorgs` will be used
- Any other optional arguments that you omit will be prompted upon execution
Expand All @@ -122,26 +138,26 @@ Please note any command with an argument in angle brackets below (ie. `<branch>`
<br>

### Navigation

1. `cd <mydir>`: directory navigation using custom aliases stored in `mydirs`
2. `back`: go back to last directory

### Pseudo-random String Generation
3. `genhex <hex-length?>`: generate and copy pseudo-random hex string of specified length (of default length 32)
3. `genb64 <base64-length?>`: generate and copy pseudo-random base64 string of specified length (of default length 32)

<!-- ### Directory Management
1. `new <mydir> <subdir>`: create new directory in location of alias
2. `delete <mydir> <subdir>`: delete directory in location of alias
3. `hide <mydir> <subdir>`: hide directory in location of alias -->

### Code Editing

1. `vsc <mydir>`: open location of alias in Visual Studio Code
2. `xc <mydir>`: open location of alias in XCode (only available for macintosh systems)

### Custom Script/Environment Execution

1. `run <myscript>`: setup and run the script saved under the given script alias

### Git Automation

1. `push <branch?>`: push changes to the given repository branch (prompts you to enter a commit message on execution and leaves a default message if left empty)
2. `pull <branch?>`: pull changes from the given repository branch
3. `ginit <newdir?>`: initialize git repository in current directory if `<newdir>` is not set, otherwise, a new directory is created called `<newdir>` and a git repository is initialized there instead
Expand All @@ -152,36 +168,51 @@ Please note any command with an argument in angle brackets below (ie. `<branch>`
7. `setup smart_commit`: this allows you to use OpenAI's ChatGPT to write commit messages for you (using `git diff` and `git status` outputs). <i>This requires an OpenAI API key.</i>

### Quick-access URLs

1. `repo`: go to the respective GitHub repository url on the default branch from your current directory
2. `branch`: go to the respective GitHub repository url on the current branch from your current directory
3. `profile`: go to your GitHub profile
4. `org <myorg?>`: go to the specified url of the GitHub organization
5. `help`: go to the wix-cli GitHub Pages url for documentation

### Data for Custom Scripting Logic
1. `user`: displays stored user-specific data such as: `username` - which represents the user's GitHub username (for configuring GitHub urls), `name` - for software licensing copyright clauses (when setting up GitHub software licenses for your repositories)

1. `user`: displays stored user-specific data such as: `username` - which represents the user's GitHub username (for configuring GitHub urls), `name` - for software licensing copyright clauses (when setting up GitHub software licenses for your repositories)
2. `myorgs`: displays stored aliases for user's GitHub organizations (for configuring GitHub urls). Please note you can use the `default` alias for your most commonly used organization, allowing you to not have to type the organization alias in cases where a `<myorg?>` argument is present
3. `mydirs`: displays stored aliases for user's directories (for efficient terminal navigation)
4. `myscripts`: displays stored aliases for user's custom scripts (for efficient environment setup or script execution)

### Editing Data for Custom Scripting Logic

1. `editd <data>`: allows the user to edit the specified piece of data (`user`, `myorgs`, `mydirs`, `myscripts`, or `todo`)
2. `edits <myscript>`: allows the user to edit the specified script (this edits the script referenced from the alias stored in `myscripts` not the `myscripts` aliases data)
3. `newscript <script-name?>`: allows the user to create a new script

### File Utilities

1. `fopen`: open the current directory in your native files application
2. `find <fname>.<fext>`: find a file inside the current directory with the respective name (use `find "*.<ext>"` for finding all files with the given extension)
3. `regex <regex?> <fname?>`: counts number of regex matches found in the given file
4. `rgxmatch <regex?> <fname?>`: returns strings of regex matches found in the given file

### Other Utilities
### Network Utilities

1. `ip`: get local and public IP addresses of your computer
2. `genqr <url?> <fname?>`: generate a png QR code for the specified URL
3. `wifi`: lists details about available wifi networks on your host machine
4. `wpass`: lists your saved wifi passwords
5. `speedtest`: run a network speedtest
6. `copy <string?|cmd?>`: copy a string or the output of a shell command (using $(<cmd>) syntax) to your clipboard
2. `wifi`: lists details about available wifi networks on your host machine
3. `wpass`: lists your saved wifi passwords
4. `speedtest`: run a network speedtest
5. `hardware-ports`: list your hardware network ports

### Image Utilities

1. `genqr <url?> <fname?>`: generate a png QR code for the specified URL
2. `upscale <fname?> <scale?>`: upscale an image's resolution (**does not smooth interpolated pixels**)

### Text Utilities

1. `genhex <hex-length?>`: generate and copy pseudo-random hex string of specified length (of default length 32)
2. `genb64 <base64-length?>`: generate and copy pseudo-random base64 string of specified length (of default length 32)
3. `copy <string?|cmd?>`: copy a string or the output of a shell command (using $(<cmd>) syntax) to your clipboard

<hr>

Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
numpy==1.24.2
openai==0.27.4
opencv_python==4.7.0.72
termcolor==1.1.0
40 changes: 35 additions & 5 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ warn_text() {
echo "${ORANGE}$1${RESET}"
}

setup_alias() {
envfile=$(envfile)
{ echo ""; echo "# WIX CLI"; echo "alias wix=\"source $(pwd)/wix-cli.sh\""; } >> "$envfile"
source "$envfile"
}

# INITIAL SETUP
if ! using_zsh; then
info_text "Installing dependencies..."
Expand All @@ -40,6 +46,9 @@ if mac; then
brew install speedtest --force
fi

info_text "Installing python dependencies..."
pip3 install -r requirements.txt

info_text "Setting up wix-cli..."
chmod +x wix-cli.sh

Expand All @@ -49,10 +58,22 @@ md_dir=.wix-cli-data
mkdir $md_dir
declare -a files=("git-user.txt" "git-orgs.txt" "dir-aliases.txt" "run-configs.txt" "todo.txt" ".env")
for i in "${files[@]}"; do
touch "$md_dir/$i"
chmod +rwx "$md_dir/$i"
if ! [ -f "$md_dir/$i" ]; then
touch "$md_dir/$i"
chmod +rwx "$md_dir/$i"
else
warn_text "File $i already exists. Would you like to overwrite it? [ y / n ]"
read -r overwrite_file
if [ "$overwrite_file" = "y" ]; then
rm "$md_dir/$i"
touch "$md_dir/$i"
chmod +rwx "$md_dir/$i"
fi
fi
done
mkdir $md_dir/run-configs
if ! [ -d "$md_dir/run-configs" ]; then
mkdir "$md_dir/run-configs"
fi


# GET USER SPECIFIC DETAILS
Expand Down Expand Up @@ -87,9 +108,18 @@ fi
echo ""
info_text "Okay we should be good to go!"

# ADD ALIAS TO ENV FILE
envfile=$(envfile)
{ echo ""; echo "# WIX CLI"; echo "alias wix=\"source $(pwd)/wix-cli.sh\""; } >> "$envfile"
source "$envfile"
if [ "$(alias wix)" != "" ]; then
warn_text "It looks like you already have a wix alias setup. Would you like to overwrite it? [ y / n ]"
read -r overwrite_alias
if [ "$overwrite_alias" = "y" ]; then
echo "${ORANGE}Please edit the $envfile file manually to remove your old alias${RESET}"
setup_alias
fi
else
setup_alias
fi

echo ""
info_text "WIX CLI successfully added to $envfile !"
Expand Down
53 changes: 45 additions & 8 deletions wix-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -396,19 +396,20 @@ if [ $num_args -eq 0 ]; then
echo ""
echo "v$version"
echo ""
h1_text "MAINTENANCE:"
echo "- sys-info ${ORANGE}: view shell info${RESET}"
echo "- update ${ORANGE}: update wix-cli${RESET}"
echo "- install-deps ${ORANGE}: install dependencies${RESET}"
echo ""
h1_text "DIRECTORY NAVIGATION:"
echo "- cd <mydir> ${ORANGE}: navigation${RESET}"
echo "- back ${ORANGE}: return to last dir${RESET}"
echo ""
h1_text "PSEUDO-RANDOM STRING GENERATION:"
echo "- genhex <hex-length?> ${ORANGE}: generate and copy pseudo-random hex string (of default length 32)${RESET}"
echo "- genb64 <base64-length?> ${ORANGE}: generate and copy pseudo-random base64 string (of default length 32)${RESET}"
# echo ""
# h1_text "DIR MANAGEMENT:"
# echo "- new <mydir> <subdir> ${ORANGE}: new directory${RESET}"
# echo "- delete <mydir> <subdir> ${ORANGE}: delete dir${RESET}"
# echo "- hide <mydir> <subdir> ${ORANGE}: hide dir${RESET}"
echo ""
h1_text "CODE:"
echo "- vsc <mydir> ${ORANGE}: open directory in Visual Studio Code${RESET}"
if using_zsh; then
Expand Down Expand Up @@ -452,13 +453,20 @@ if [ $num_args -eq 0 ]; then
echo "- regex \"<regex?>\" \"<fname?>\" ${ORANGE}: return the number of regex matches in the given file${RESET}"
echo "- rgxmatch \"<regex?>\" \"<fname?>\"${ORANGE}: return the string matches of your regex in the given file${RESET}"
echo ""
h1_text "OTHER UTILITIES:"
echo "- genqr <url?> <fname?> ${ORANGE}: generate a png QR code for the specified URL${RESET}"
echo "- upscale <fname?> <scale?> ${ORANGE}: upscale an image's resolution (**does not smooth interpolated pixels**)${RESET}"
h1_text "NETWORK UTILITIES:"
echo "- ip ${ORANGE}: get local and public IP addresses of your computer${RESET}"
echo "- wifi ${ORANGE}: list information on your available wifi networks${RESET}"
echo "- wpass ${ORANGE}: list your saved wifi passwords${RESET}"
echo "- speedtest ${ORANGE}: run a network speedtest${RESET}"
echo "- hardware-ports ${ORANGE}: list your hardware ports${RESET}"
echo ""
h1_text "IMAGE UTILITIES:"
echo "- genqr <url?> <fname?> ${ORANGE}: generate a png QR code for the specified URL${RESET}"
echo "- upscale <fname?> <scale?> ${ORANGE}: upscale an image's resolution (**does not smooth interpolated pixels**)${RESET}"
echo ""
h1_text "TEXT UTILITIES:"
echo "- genhex <hex-length?> ${ORANGE}: generate and copy pseudo-random hex string (of default length 32)${RESET}"
echo "- genb64 <base64-length?> ${ORANGE}: generate and copy pseudo-random base64 string (of default length 32)${RESET}"
echo "- copy <string?|cmd?> ${ORANGE}: copy a string or the output of a shell command (using \$(<cmd>) syntax) to your clipboard${RESET}"
echo ""
# h1_text "CLI management:"
Expand Down Expand Up @@ -810,7 +818,18 @@ elif [ "$1" = "ip" ]; then
echo ""

elif [ "$1" = "wifi" ]; then
python3 "${scriptdir}/wifi_sniffer.py"
if mac; then
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport scan
else
python3 "${scriptdir}/wifi_sniffer.py"
fi

elif [ "$1" = "hardware-ports" ]; then
if mac; then
networksetup -listallhardwareports
else
echo "Not supported on this OS"
fi

elif [ "$1" = "wpass" ]; then
info_text "Listing saved Wifi passwords:"
Expand Down Expand Up @@ -967,6 +986,24 @@ elif [ "$1" = "update" ]; then
git pull origin master
cd -

elif [ "$1" = "install-deps" ]; then
if ! using_zsh; then
info_text "Installing dependencies..."
sudo apt-get install xclip
curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash
sudo apt-get install speedtest
fi

if mac; then
info_text "Installing dependencies..."
brew install xclip jq
brew tap teamookla/speedtest
brew install speedtest --force
fi

info_text "Installing python dependencies..."
pip3 install -r requirements.txt

# EXTRA FEATURE SETUP

elif [ "$1" = "setup" ]; then
Expand Down