diff --git a/.github/README.md b/.github/README.md index 3b2d180..8da9c44 100644 --- a/.github/README.md +++ b/.github/README.md @@ -4,7 +4,7 @@ Optimize your development productivity in the terminal
-[![CODEQL](https://github.com/hwixley/wix-cli/actions/workflows/github-code-scanning/codeql/badge.svg)](https://hwixley.github.io/wix-cli/) [![Deploy Jekyll GH-Pages](https://github.com/hwixley/WIX-CLI/actions/workflows/jekyll-gh-pages.yml/badge.svg)](https://github.com/hwixley/WIX-CLI/actions/workflows/jekyll-gh-pages.yml) [![Generate Stdout Image](https://github.com/hwixley/WIX-CLI/actions/workflows/main.yml/badge.svg)](https://github.com/hwixley/WIX-CLI/actions/workflows/main.yml)
![License](https://img.shields.io/badge/License-MIT-purple?labelColor=gray&style=flat) ![Version](https://img.shields.io/badge/Version-1.1.0-blue?labelColor=gray&style=flat) ![Platforms](https://img.shields.io/badge/Platforms-BASH%20&%20ZSH-orange?labelColor=gray&style=flat) +[![CODEQL](https://github.com/hwixley/wix-cli/actions/workflows/github-code-scanning/codeql/badge.svg)](https://hwixley.github.io/wix-cli/) [![Deploy Jekyll GH-Pages](https://github.com/hwixley/WIX-CLI/actions/workflows/jekyll-gh-pages.yml/badge.svg)](https://github.com/hwixley/WIX-CLI/actions/workflows/jekyll-gh-pages.yml) [![Generate Stdout Image](https://github.com/hwixley/WIX-CLI/actions/workflows/main.yml/badge.svg)](https://github.com/hwixley/WIX-CLI/actions/workflows/main.yml)
![License](https://img.shields.io/badge/License-MIT-purple?labelColor=gray&style=flat) ![Version](https://img.shields.io/badge/Version-2.0.0-blue?labelColor=gray&style=flat) ![Platforms](https://img.shields.io/badge/Platforms-BASH%20&%20ZSH-orange?labelColor=gray&style=flat)

@@ -19,6 +19,7 @@ Optimize your development productivity in the terminal - [Table of Contents](#table-of-contents) - [What It Does](#what-it-does) - [Why It Was Made](#why-it-was-made) + - [Support This Project](#support-this-project) - [Dependencies](#dependencies) - [Installation](#installation) - [Extra Feature Setup](#extra-feature-setup) @@ -42,7 +43,6 @@ Optimize your development productivity in the terminal - [Help Utilities](#help-utilities) - [Bugs, New Features, \& Questions](#bugs-new-features--questions) - [Make A Contribution](#make-a-contribution) - - [Support This Project](#support-this-project)


diff --git a/argparse.sh b/argparse.sh index 4f6414c..619ad66 100644 --- a/argparse.sh +++ b/argparse.sh @@ -1,63 +1,20 @@ #!/bin/bash # CLI CONSTS -version="1.1.0" +version="2.0.0" num_args=$# -mypath=$(readlink -f "${BASH_SOURCE:-$0}") date=$(date) year="${date:24:29}" -mydir=$(dirname "$mypath") -datadir=$mydir/.wix-cli-data -scriptdir=$mydir/scripts - -source $mydir/functions.sh - -# DATA -declare -A user -declare -a user_lines user_lines=() -while IFS='' read -r line || [[ -n "$line" ]]; do - user_lines+=("$line") -done < "$datadir/git-user.txt" -for line in "${user_lines[@]}"; do - key=${line%%=*} - value=${line#*=} - user[$key]=$value -done - -declare -A myorgs -declare -a org_lines org_lines=() -while IFS='' read -r line || [[ -n "$line" ]]; do - org_lines+=("$line") -done < "$datadir/git-orgs.txt" -for line in "${org_lines[@]}"; do - key=${line%%=*} - value=${line#*=} - myorgs[$key]=$value -done - -declare -A mydirs -declare -a dir_lines dir_lines=() -while IFS='' read -r line || [[ -n "$line" ]]; do - dir_lines+=("$line") -done < "$datadir/dir-aliases.txt" -for line in "${dir_lines[@]}"; do - key=${line%%=*} - value=${line#*=} - mydirs[$key]=$value -done - -declare -A myscripts -declare -a script_lines script_lines=() -while IFS='' read -r line || [[ -n "$line" ]]; do - script_lines+=("$line") -done < "$datadir/run-configs.txt" -for line in "${script_lines[@]}"; do - key=${line%%=*} - value=${line#*=} - myscripts[$key]=$value -done +# Load bash classes +source $(dirname ${BASH_SOURCE[0]})/src/classes/sys/sys.h +sys sys +source $(dirname ${BASH_SOURCE[0]})/src/classes/wgit/wgit.h +wgit wgit +source $(dirname ${BASH_SOURCE[0]})/src/classes/wixd/wixd.h +wixd wixd +# Load source git data branch="" if git rev-parse --git-dir > /dev/null 2>&1; then branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p') @@ -67,1231 +24,24 @@ repo_url=${remote#"git@github.com:"} repo_url=${repo_url%".git"} -# MODULAR FUNCTIONS - -clipboard() { - if command -v pbcopy >/dev/null 2>&1; then - info_text "This has been saved to your clipboard!" - echo "$1" | pbcopy - elif command -v xclip >/dev/null 2>&1; then - info_text "This has been saved to your clipboard!" - echo "$1" | xclip -selection c - else - warn_text "Clipboard not supported on this system, please install xclip or pbcopy." - fi -} - -editfile() { - if using_zsh; then - vi "$1" - else - gedit "$1" - fi -} - -arggt() { - if [ "$num_args" -gt "$1" ]; then - return 0 - else - return 1 - fi -} - -direxists() { - if [[ -v mydirs[$1] ]]; then - return 0 - else - return 1 - fi -} - -orgexists() { - if [[ -v myorgs[$1] ]]; then - return 0 - else - return 1 - fi -} - -scriptexists() { - if [[ -v myscripts[$1] ]]; then - return 0 - else - return 1 - fi -} - -check_keystore() { - envfile="$datadir/.env" - if [[ -f "$envfile" ]]; then - # Check if key-value pair exists in .env file - if grep -q "^$1=" "$envfile"; then - # Prompt user to replace the existing value - read -rp "${GREEN}Key \"$1\" already exists. Do you want to replace the value? (y/n):${RESET} " choice - if [[ $choice == "y" || $choice == "Y" ]]; then - if [ -n "$2" ]; then - # Replace the value in .env - sed -i "s/^$1=.*/$1=$2/" "$envfile" - info_text "Value for key \"$1\" replaced successfully!" - else - # Prompt user to enter the value - read -rp "${GREEN}Enter the value for \"$1\":${RESET} " value - - # Replace the value in .env - sed -i "s/^$1=.*/$1=$value/" "$envfile" - info_text "Value for key \"$1\" replaced successfully!" - fi - else - info_text "Value for key \"$1\" not replaced." - fi - else - if [ -n "$2" ]; then - # Append key-value pair to .env - echo "$1=$2" >> "$envfile" - info_text "Value for key \"$1\" appended successfully!" - else - # Prompt user to enter the value - read -rp "${GREEN}Enter the value for \"$1\":${RESET} " value - - # Append key-value pair to .env - echo "$1=$value" >> "$envfile" - info_text "Value for key \"$1\" appended successfully!" - fi - fi - else - if [ -n "$2" ]; then - # Create .env file and add the key-value pair - echo "$1=$2" > "$envfile" - info_text ".env file created successfully!" - info_text "Value for key \"$1\" appended successfully!" - else - # Prompt user to enter the value - read -rp "${GREEN}Enter the value for \"$1\":${RESET} " value - - # Create .env file and add the key-value pair - echo "$1=$value" > "$envfile" - info_text ".env file created successfully!" - info_text "Value for key \"$1\" appended successfully!" - fi - fi - echo "" -} - -is_git_repo() { - if git rev-parse --git-dir > /dev/null 2>&1; then - branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p') - fi - if ! empty "$branch" ; then - return 0 - else - error_text "This is not a git repository..." - return 1 - fi -} - - -commit() { - git add . - if empty "$1" ; then - if [ -f "${datadir}/.env" ]; then - if grep -q "OPENAI_API_KEY=" "${datadir}/.env" && grep -q "USE_SMART_COMMIT=true" "${datadir}/.env" ; then - IFS=$'\n' lines=($(python3 "$scriptdir/services/openai_service.py" "smart")) - h2_text "GPT-3 Suggestion" - if using_zsh; then - h2_text "Title:${RESET} ${lines[1]}" - h2_text "Description:${RESET} ${lines[2]}" - echo "" - info_text "Press enter to use this suggestion or type your own description." - read -r description - git commit -m "${description:-${lines[1]}}" -m "${lines[2]}" - else - h2_text "Title:${RESET} ${lines[0]}" - h2_text "Description:${RESET} ${lines[1]}" - echo "" - info_text "Press enter to use this suggestion or type your own description." - read -r description - git commit -m "${description:-${lines[0]}}" -m "${lines[1]}" - fi - else - info_text "Provide a commit description: (defaults to 'wix-cli quick commit')" - read -r description - git commit -m "${description:-wix-cli quick commit}" - fi - else - info_text "Provide a commit description: (defaults to 'wix-cli quick commit')" - read -r description - git commit -m "${description:-wix-cli quick commit}" - fi - else - git commit -m "${1:-wix-cli quick commit}" - fi -} - -push() { - if [ "$1" != "$branch" ]; then - git checkout "$1" - fi - commit "$2" - git push origin "$1" -} - -npush() { - git checkout -b "$1" - commit "$2" - git push origin "$1" -} - -pull() { - if [ "$1" != "$branch" ]; then - git checkout "$1" - fi - git pull origin "$1" -} - -bpr() { - npush "$1" - info_text "Creating PR for $branch in $repo_url..." - openurl "https://github.com/$repo_url/pull/new/$1" -} - -ginit() { - git init - if empty "$2" ; then - info_text "Provide a name for this repository:" - read -r rname - echo "# $rname" >> README.md - info_text "Would you like to add a MIT license to this repository? [ Yy / Nn ]" - read -r rlicense - if [ "$rlicense" = "y" ] || [ "$rlicense" = "Y" ] - then - touch "LICENSE.md" - echo -e "MIT License\n\nCopyright (c) ${user["name"]} $year\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE." >> "LICENSE.md" - fi - commit "wix-cli: first commit" - git remote add origin "git@github.com:$1/$rname.git" - openurl "https://github.com/$3" - else - echo "# $2" >> README.md - commit "wix-cli: first commit" - git remote add origin "git@github.com:$1/$2.git" - openurl "https://github.com/$3" - fi -} - -# COMMAND FUNCTIONS -wix_cd() { - if arggt "1" ; then - if direxists "$1" ; then - destination="${mydirs[$1]/~/${HOME}}" - if ! empty "$2" ; then - destination="${mydirs[$1]/~/${HOME}}/$2" - fi - info_text "Travelling to -> $destination" - eval cd "$destination" || (error_text "The path $destination does not exist" && return 1) - return 0 - else - error_text - return 1 - fi - else - info_text "Where do you want to go?" - read -r dir - if direxists "$dir" ; then - info_text "Travelling to -> ${mydirs[$dir]}" - cd "${mydirs[$dir]:?}" || exit - return 0 - else - error_text - return 1 - fi - fi -} - -wix_new() { - if direxists "$1" ; then - if empty "$2" ; then - info_text "Provide a name for this directory:" - read -r dname - info_text "Generating new dir (${mydirs[$1]}/$dname)..." - mkdir "${mydirs[$1]:?}/$dname" - cd "${mydirs[$1]:?}/$dname" || exit - else - info_text "Generating new dir (${mydirs[$1]}/$2)..." - mkdir "${mydirs[$1]:?}/$2" - cd "${mydirs[$1]:?}/$2" || exit - fi - return 0 - else - error_text - return 1 - fi -} - -wix_run() { - if scriptexists "$1"; then - info_text "Running $1 script!" - source "$datadir/run-configs/${myscripts[$1]}.sh" - else - error_text "This is only supported for gs currently" - fi -} - -wix_delete() { - if direxists "$1" ; then - if empty "$2" ; then - error_text "You did not provide a path in this directory to delete, try again..." - else - error_text "Are you sure you want to delete ${mydirs[$1]}/$2? [ Yy / Nn]" - read -r response - if [ "$response" = "y" ] || [ "$response" = "Y" ] - then - error_text "Are you really sure you want to delete ${mydirs[$1]}/$2? [ Yy / Nn]" - read -r response - if [ "$response" = "y" ] || [ "$response" = "Y" ] - then - error_text "Deleting ${mydirs[$1]}/$2" - rm -rf "${mydirs[$1]:?}/$2" - fi - fi - fi - else - error_text - fi -} - -# GITHUB AUTOMATION COMMAND FUNCTIONS -wix_ginit() { - if ! empty "$1"; then - mkdir "$1" - cd "$1" || return 1 - fi - - if empty "$branch" ; then - info_text "Would you like you to host this repository under a GitHub organization? [ Yy / Nn ]" - read -r response - if [ "$response" = "y" ] || [ "$response" = "Y" ] - then - echo "" - h1_text "Your saved GitHub organization aliases:" - for key in "${!myorgs[@]}"; do - echo "$key: ${myorgs[$key]}" - done - echo "" - info_text "Please enter the organization name alias you would like to use:" - read -r orgalias - if orgexists "$orgalias" ; then - ginit "${myorgs[$orgalias]}" "$2" "organizations/${myorgs[$orgalias]}/repositories/new" - else - ginit "${user[username]}" "$2" "new" - fi - else - ginit "${user[username]}" "$2" "new" - fi - else - error_text "This is already a git repository..." - fi -} - -wix_gnew() { - if wix_new "$1" "$2" ; then - wix_ginit "$1" "$2" - fi -} - -giturl() { - if is_git_repo ; then - openurl "$1" - fi -} - -webtext() { - lynx -dump -cookies "$1" -} - -command_info() { - echo "Welcome to the..." - echo "" - info_text " ${CYAN}Y${BLUE}8b ${CYAN}Y${BLUE}8b ${CYAN}Y${BLUE}888P ${CYAN}8${BLUE}88 ${CYAN}Y${BLUE}8b Y8P${GREEN} e88'Y88 888 888 " - info_text " ${CYAN}Y${BLUE}8b ${CYAN}Y${BLUE}8b ${CYAN}Y${BLUE}8P ${CYAN}8${BLUE}88 ${CYAN}Y${BLUE}8b Y${GREEN} d888 'Y 888 888 " - info_text " ${CYAN}Y${BLUE}8b ${CYAN}Y${BLUE}8b ${CYAN}Y${BLUE} ${CYAN}8${BLUE}88 ${CYAN}Y${BLUE}8b${GREEN} C8888 888 888 " - info_text " ${CYAN}Y${BLUE}8b ${CYAN}Y${BLUE}8b ${CYAN}8${BLUE}88 e ${CYAN}Y${BLUE}8b${GREEN} Y888 ,d 888 ,d 888 " - info_text " ${CYAN}Y${BLUE}8P ${CYAN}Y${BLUE} ${CYAN}8${BLUE}88 d8b ${CYAN}Y${BLUE}8b${GREEN} \"88,d88 888,d88 888 " - 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 ${ORANGE}: navigation${RESET}" - echo "- back ${ORANGE}: return to last dir${RESET}" - echo "" - h1_text "CODE:" - echo "- vsc ${ORANGE}: open directory in Visual Studio Code${RESET}" - if using_zsh; then - echo "- xc ${ORANGE}: open directory in XCode${RESET}" - fi - echo "- run ${ORANGE}: setup and run environment${RESET}" - echo "" - h1_text "GITHUB AUTOMATION:" - echo "- push ${ORANGE}: push changes to repo branch${RESET}" - echo "- pull ${ORANGE}: pull changes from repo branch${RESET}" - echo "- ginit ${ORANGE}: setup git repo in existing/new directory${RESET}" - echo "- nb ${ORANGE}: create new branch${RESET}" - echo "- pr ${ORANGE}: create PR for branch${RESET}" - echo "- bpr ${ORANGE}: checkout changes to new branch and create PR${RESET}" - echo "- commits ${ORANGE}: view commit history${RESET}" - echo "- lastcommit ${ORANGE}: view last commit${RESET}" - echo "- setup smart_commit ${ORANGE}: setup smart commit${RESET}" - echo "" - h1_text "URLS:" - echo "- repo ${ORANGE}: go to git repo URL${RESET}" - echo "- branch ${ORANGE}: go to git branch URL${RESET}" - echo "- prs ${ORANGE}: go to git repo Pull Requests URL${RESET}" - echo "- actions ${ORANGE}: go to git repo Actions URL${RESET}" - echo "- issues ${ORANGE}: go to git repo Issues URL${RESET}" - echo "- notifs ${ORANGE}: go to git notifications URL${RESET}" - echo "- profile ${ORANGE}: go to git profile URL${RESET}" - echo "- org ${ORANGE}: go to git org URL${RESET}" - echo "- help ${ORANGE}: go to wix-cli GitHub Pages URL${RESET}" - echo "" - h1_text "MY DATA:" - echo "- user ${ORANGE}: view your user-specific data (ie. name, GitHub username)${RESET}" - echo "- myorgs ${ORANGE}: view your GitHub organizations and their aliases${RESET}" - echo "- mydirs ${ORANGE}: view your directory aliases${RESET}" - echo "- myscripts ${ORANGE}: view your script aliases${RESET}" - echo "- todo ${ORANGE}: view your to-do list${RESET}" - echo "" - h1_text "MANAGE MY DATA:" - echo "- editd ${ORANGE}: edit a piece of your data (ie. user, myorgs, mydirs, myscripts, todo)${RESET}" - echo "- edits ${ORANGE}: edit a script (you must use an alias present in myscripts)${RESET}" - echo "- newscript ${ORANGE}: create a new script${RESET}" - echo "" - h1_text "ENV/KEYSTORE:" - echo "- keystore ${ORANGE}: add a key-value pair to your keystore${RESET}" - echo "- setup openai_key ${ORANGE}: setup your OpenAI API key${RESET}" - echo "- setup smart_commit ${ORANGE}: setup your smart commit${RESET}" - echo "" - h1_text "FILE UTILITIES:" - echo "- fopen ${ORANGE}: open current directory in files application${RESET}" - echo "- find \"\" ${ORANGE}: find a file inside the current directory using regex${RESET}" - echo "- regex \"\" \"\" ${ORANGE}: return the number of regex matches in the given file${RESET}" - echo "- rgxmatch \"\" \"\"${ORANGE}: return the string matches of your regex in the given file${RESET}" - echo "- encrypt ${ORANGE}: GPG encrypt a file/directory (saves as a new .gpg file)${RESET}" - echo "- decrypt ${ORANGE}: GPG decrypt a file (must be a .gpg file)${RESET}" - echo "" - 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 ${ORANGE}: generate a png QR code for the specified URL${RESET}" - echo "- upscale ${ORANGE}: upscale an image's resolution (**does not smooth interpolated pixels**)${RESET}" - echo "" - h1_text "TEXT UTILITIES:" - echo "- genpass ${ORANGE}: generate and copy random password string (of default length 16)${RESET}" - echo "- genhex ${ORANGE}: generate and copy random hex string (of default length 32)${RESET}" - echo "- genb64 ${ORANGE}: generate and copy random base64 string (of default length 32)${RESET}" - echo "- copy ${ORANGE}: copy a string or the output of a shell command (using \$() syntax) to your clipboard${RESET}" - echo "- lastcmd ${ORANGE}: copy the last command you ran to your clipboard${RESET}" - echo "" - h1_text "WEB UTILITIES:" - echo "- webtext ${ORANGE}: extract readable text from a website" - echo "" - h1_text "MISC UTILITIES:" - echo "- weather ${ORANGE}: get the weather forecast for your current location${RESET}" - echo "- moon ${ORANGE}: get the current moon phase${RESET}" - echo "- leap-year ${ORANGE}: tells you the next leap year" - echo "" - h1_text "HELP UTILITIES:" - echo "- explain \"\" ${ORANGE}: explain the syntax of the input bash command${RESET}" - echo "- ask-gpt ${ORANGE}: start a conversation with OpenAI's ChatGPT in the terminal${RESET}" - echo "- google \"\" ${ORANGE}: google a query${RESET}" - echo "" -} - - -# DEFAULT - if [ $num_args -eq 0 ]; then - command_info - -# GENERAL - -elif [ "$1" = "sys-info" ]; then - if using_zsh; then - echo "ZSH (0_0)" - else - echo "BASH (-_-)" - fi - -elif [ "$1" = "cd" ]; then - wix_cd "$2" - -elif [ "$1" = "back" ]; then - cd - || error_text "Failed to execute 'cd -'..." - -elif [ "$1" = "new" ]; then - wix_new "$2" "$3" - -elif [ "$1" = "run" ]; then - wix_run "$2" - -elif [ "$1" = "vsc" ]; then - if direxists "$2"; then - wix_cd "$2" - info_text "Opening up VSCode editor..." - code . - else - error_text "Error: this directory alias does not exist, please try again" - fi - -elif [ "$1" = "delete" ]; then - wix_delete "$2" "$3" - -elif [ "$1" = "hide" ]; then - echo "not implemented yet" - -elif [ "$1" = "genpass" ]; then - pass_size=16 - if arggt "1"; then - if ! [[ "$2" =~ ^[0-9]+$ ]]; then - error_text "Error: the password-length argument must be an integer" - return 1 - else - pass_size=$2 - fi - fi - pass=$(python3 "${scriptdir}/random_string_gen.py" "$pass_size") - info_text "Your random password string is: ${RESET}$pass" - clipboard "$pass" - -elif [ "$1" = "genhex" ]; then - hex_size=32 - if arggt "1"; then - if ! [[ "$2" =~ ^[0-9]+$ ]]; then - error_text "Error: the hex-length argument must be an integer" - return 1 - else - hex_size=$2 - fi - fi - pass=$(openssl rand -hex "$hex_size") - truncated_pass="${pass:0:$hex_size}" - info_text "Your random hex string is: ${RESET}$truncated_pass" - clipboard "$truncated_pass" - -elif [ "$1" = "genb64" ]; then - hex_size=32 - if arggt "1"; then - if ! [[ "$2" =~ ^[0-9]+$ ]]; then - error_text "Error: the base64-length argument must be an integer" - return 1 - else - hex_size=$2 - fi - fi - pass=$(openssl rand -base64 "$hex_size") - truncated_pass="${pass:0:$hex_size}" - info_text "Your random base64 string is: ${RESET}$truncated_pass" - clipboard "$truncated_pass" - -# CLI MANAGEMENT - -elif [ "$1" = "edit" ]; then - warn_text "Edit wix-cli script..." - editfile "$mypath" - info_text "Saving changes to $mypath..." - source $(envfile) - -elif [ "$1" = "save" ]; then - info_text "Sourcing bash :)" - source $(envfile) - -elif [ "$1" = "cat" ]; then - cat "$mypath" - -elif [ "$1" = "-v" ] || [ "$1" = "--version" ] || [ "$1" = "version" ]; then - echo "v$version" - -# elif [ "$1" = "cdir" ]; then -# info_text "Enter an alias for your new directory:" -# read -r alias -# info_text "Enter the directory:" -# read -r i_dir -# info_text "Adding $alias=$i_dir to custom dirs" -# sed -i "${insertline}imydirs["$alias"]=$i_dir" $mypath -# wix save - -# elif [ "$1" = "mydirs" ]; then -# for x in $dirkeys; do printf "[%s]=%s\n" "$x" "${mydirs[$x]}" ; done - - -# GITHUB AUTOMATION - -# elif [ "$1" = "gnew" ]; then -# wix_gnew "$2" "$3" - -elif [ "$1" = "ginit" ]; then - wix_ginit "$2" - -elif [ "$1" = "push" ]; then - if arggt "1" ; then - push "$2" - else - push "$branch" - fi - -elif [ "$1" = "pull" ]; then - if arggt "1" ; then - pull "$2" - else - pull "$branch" - fi - -elif [ "$1" = "mpull" ]; then - if [ "$(git branch --list master)" ]; then - pull "master" - elif [ "$(git branch --list main)" ]; then - pull "main" - else - warn_text "No master or main branch found..." - fi - -elif [ "$1" = "repo" ]; then - info_text "Redirecting to $repo_url..." - giturl "https://github.com/$repo_url" - -elif [ "$1" = "branch" ]; then - info_text "Redirecting to $branch on $repo_url..." - giturl "https://github.com/$repo_url/tree/$branch" - -elif [ "$1" = "actions" ]; then - info_text "Redirecting to Action Workflows on $repo_url..." - giturl "https://github.com/$repo_url/actions" - -elif [ "$1" = "issues" ]; then - info_text "Redirecting to Issues on $repo_url..." - giturl "https://github.com/$repo_url/issues" - -elif [ "$1" = "prs" ]; then - info_text "Redirecting to Pull Requests on $repo_url..." - giturl "https://github.com/$repo_url/pulls" - -elif [ "$1" = "notifs" ]; then - info_text "Redirecting to your Notifications..." - giturl "https://github.com/notifications" - -elif [ "$1" = "commits" ]; then - git log --pretty=format:"${GREEN}%H${RESET} - ${BLUE}%an${RESET}, ${ORANGE}%cr [%cd]${RESET} : %s" - -elif [ "$1" = "lastcommit" ]; then - clipboard "$(git rev-parse HEAD)" - git show HEAD - -elif [ "$1" = "nb" ]; then - if arggt "1" ; then - npush "$2" - else - info_text "Provide a branch name:" - read -r name - if [ "$name" != "" ]; then - npush "$name" - else - error_text "Invalid branch name" - fi - fi - -elif [ "$1" = "pr" ]; then - info_text "Creating PR for $branch in $repo_url..." - giturl "https://github.com/$repo_url/pull/new/$branch" - -elif [ "$1" = "bpr" ]; then - if is_git_repo ; then - if arggt "1" ; then - bpr "$2" - else - info_text "Provide a branch name:" - read -r name - if [ "$name" != "" ]; then - bpr "$name" - fi - fi - fi - -elif [ "$1" = "profile" ]; then - openurl "https://github.com/${user[username]}" - -elif [ "$1" = "org" ]; then - if arggt "1"; then - if orgexists "$2"; then - giturl "https://github.com/${myorgs[$2]}" - else - error_text "That organisation does not exist..." - info_text "Execute 'wix myorgs' to see your saved organisations" - fi - else - giturl "https://github.com/${myorgs[default]}" - fi - -# URLs - -elif [ "$1" = "help" ]; then - openurl "https://hwixley.github.io/WIX-CLI/index.html" + # No input - show command info + wixd.command_info -# MY DATA - -elif [ "$1" = "user" ]; then - cat "$datadir/git-user.txt" - -elif [ "$1" = "mydirs" ]; then - cat "$datadir/dir-aliases.txt" - -elif [ "$1" = "myorgs" ]; then - cat "$datadir/git-orgs.txt" - -elif [ "$1" = "myscripts" ]; then - cat "$datadir/run-configs.txt" - -elif [ "$1" = "todo" ]; then - cat "$datadir/todo.txt" - -elif [ "$1" = "editd" ]; then - data_to_edit="$2" - if ! arggt "1"; then - info_text "What data would you like to edit?" - read -r data_to_edit_prompt - data_to_edit=$data_to_edit_prompt - - declare -a datanames - datanames=( "user" "myorgs" "mydirs" "myscripts" ) - if ! printf '%s\0' "${datanames[@]}" | grep -Fxqz -- "$data_to_edit_prompt"; then - error_text "'$data_to_edit_prompt' is not a valid piece of data, please try one of the following: ${datanames[*]}" - return 1 - fi - fi - if [ "$data_to_edit" = "user" ]; then - editfile "$datadir/git-user.txt" - elif [ "$data_to_edit" = "myorgs" ]; then - editfile "$datadir/git-orgs.txt" - elif [ "$data_to_edit" = "mydirs" ]; then - editfile "$datadir/dir-aliases.txt" - elif [ "$data_to_edit" = "myscripts" ]; then - editfile "$datadir/run-configs.txt" - elif [ "$data_to_edit" = "todo" ]; then - editfile "$datadir/todo.txt" - fi - -elif [ "$1" = "create-script" ]; then - script_name="$2" - if ! arggt "1"; then - info_text "Enter the name of the script you would like to add:" - read -r script_name_prompt - script_name=$script_name_prompt - fi - fname="$datadir/run-configs/$script_name.sh" - touch "$fname" - chmod u+x "$fname" - editfile "$fname" - -elif [ "$1" = "edits" ]; then - script_to_edit="$2" - if ! arggt "1"; then - info_text "What script would you like to edit?" - read -r script_to_edit_prompt - script_to_edit=$script_to_edit_prompt - fi - if scriptexists "$script_to_edit"; then - info_text "Editing $script_to_edit script..." - editfile "$datadir/run-configs/$script_to_edit.sh" - else - error_text "This script does not exist... Please try again" - fi - -elif [ "$1" = "newscript" ]; then - name="$2" - if ! arggt "1"; then - info_text "What would you like to call your script? (no spaces)" - read -r name_prompt - name="$name_prompt" - fi - if [ -f "$datadir/$name.sh" ]; then - error_text "Error: this script name already exists" - else - info_text "Creating new script..." - echo "$name=$name" >> "$datadir/run-configs.txt" - touch "$datadir/run-configs/$name.sh" - editfile "$datadir/run-configs/$name.sh" - fi - -# FILE CREATION - -elif [ "$1" = "newf" ]; then - fext="sh" - if arggt "1"; then - fext="$2" - else - info_text "Enter the file extension you would like to use:" - read -r fext - fi - if [[ "${exts[*]}" =~ $fext ]]; then - info_text "Enter a filename for your $1 file:" - read -r fname - info_text "Creating $fname.$1" - touch "$fname.$1" - editfile "$fname.$1" - fi - -# FIND FILE - -elif [ "$1" = "find" ]; then - if arggt "1"; then - # find . -type f -name "$2" - find . -regextype posix-extended -regex ".*$2.*" - else - info_text "Enter the regex you would like to use:" - read -r regex - # find . -type f -name "$fname" - find . -regextype posix-extended -regex "$regex" - fi - -# CLIPBOARD - -elif [ "$1" = "copy" ]; then - if arggt "1"; then - if [[ "$2" =~ ^\$\(.*\)$ ]]; then - DATA="$2" - clipboard "$DATA" - else - clipboard "$2" - fi - else - info_text "Enter the text you would like to copy to your clipboard:" - read -r text - clipboard "$text" - fi - -# LAST COMMAND - -elif [ "$1" = "lastcmd" ]; then - lastcmd=$(fc -ln -1) - trimmed=$(echo "$lastcmd" | xargs) - clipboard "$trimmed" - -# IP ADDRESS - -elif [ "$1" = "ip" ]; then - echo "" - info_text "Local IPs:" - if mac; then - ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}' - else - hostname -I - fi - echo "" - info_text "Public IP:" - public_ip=$(curl ifconfig.co/json) - ip=$(echo "$public_ip" | jq -r '.ip') - city=$(echo "$public_ip" | jq -r '.city') - region=$(echo "$public_ip" | jq -r '.region_name') - zip=$(echo "$public_ip" | jq -r '.zip_code') - country=$(echo "$public_ip" | jq -r '.country') - lat=$(echo "$public_ip" | jq -r '.latitude') - long=$(echo "$public_ip" | jq -r '.longitude') - time_zone=$(echo "$public_ip" | jq -r '.time_zone') - asn_org=$(echo "$public_ip" | jq -r '.asn_org') - echo "" - echo "IP: $ip" - echo "" - echo "${ORANGE}Address:${RESET} $city, $region, $zip, $country" - echo "${ORANGE}Latitude & Longitude:${RESET} ($lat, $long)" - echo "${ORANGE}Timezone:${RESET} $time_zone" - echo "${ORANGE}ASN Org:${RESET} $asn_org" - - echo "" - info_text "Eth0 MAC Address:" - if mac; then - ifconfig en1 | awk '/ether/{print $2}' - else - cat "/sys/class/net/$(ip route show default | awk '/default/ {print $5}')/address" - fi - echo "" - -elif [ "$1" = "wifi" ]; then - 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 - if mac; then - info_text "Enter the SSID of the network you would like to get the password for:" - read -r ssid - info_text "Getting password for $ssid..." - security find-generic-password -ga "$ssid" | grep "password:" - echo "" - else - info_text "Listing saved Wifi passwords:" - sudo grep -r '^psk=' /etc/NetworkManager/system-connections/ - fi - -elif [ "$1" = "speedtest" ]; then - info_text "Running speedtest..." - speedtest - -# QR CODE - -elif [ "$1" = "genqr" ]; then - link="$2" - fname="$3" - if ! arggt "1"; then - info_text "Enter the URL you would like to link to:" - read -r url - link="$url" - - if ! arggt "2"; then - info_text "Enter the name for your QR code:" - read -r qrname - fname="$qrname" - fi - fi - info_text "Generating a QR code..." - qrencode -o "$fname.png" "$link" - display "$fname.png" - -# UPSCALE PHOTO - -elif [ "$1" = "upscale" ]; then - fname="$2" - alpha="$3" - if ! arggt "1"; then - info_text "Enter the file you would like to upscale:" - read -r url - fname="$url" - - if ! arggt "2"; then - info_text "Enter the scale multiplier:" - read -r mult - alpha="$mult" - fi - fi - info_text "Upscaling $fname..." - python3 "$scriptdir/photo-upscale.py" "$fname" "$alpha" - -# OPEN FILE - -elif [ "$1" = "fopen" ]; then - if arggt "1"; then - dir="$2" - if direxists "$dir"; then - mydir="${mydirs[$dir]/\~/${HOME}}" - info_text "Opening $mydir..." - openfile "$mydir" - else - error_text "Directory alias does not exist" - fi - else - info_text "Opening current directory..." - openfile "$(pwd)" - fi - -# REGEX SEARCH - -elif [ "$1" = "regex" ]; then - if arggt "1"; then - regex="$2" - if arggt "2"; then - fname="$3" - if [ -f "$fname" ]; then - info_text "Searching for $regex in $fname..." && echo "" - grep "$regex" "$fname" - echo "" && info_text "Number of matches:" - grep -c "$regex" "$fname" - else - error_text "File does not exist" - fi - else - info_text "Enter the filename you would like to search:" - read -r fname - if [ -f "$fname" ]; then - info_text "Searching for $regex in $fname..." && echo "" - grep "$regex" "$fname" - echo "" && info_text "Number of matches:" - grep -c "$regex" "$fname" - else - error_text "File does not exist" - fi - fi - else - info_text "Enter the regex you would like to search for:" - read -r regex - info_text "Enter the filename you would like to search:" - read -r fname - if [ -f "$fname" ]; then - info_text "Searching for $regex in $fname..." - grep -E "$regex" "$fname" - else - error_text "File does not exist" - fi - fi - -elif [ "$1" = "rgxmatch" ]; then - if arggt "1"; then - regex="$2" - if arggt "2"; then - fname="$3" - if [ -f "$fname" ]; then - info_text "Searching for $regex in $fname..." - echo "" - info_text "Matches: " - data=$(cat "$fname") - [[ "$data" =~ $regex ]] - token=$(echo "${BASH_REMATCH[1]}") - echo "$token" - clipboard "$token" - else - error_text "File does not exist" - fi - else - info_text "Enter the filename you would like to search:" - read -r fname - if [ -f "$fname" ]; then - info_text "Searching for $regex in $fname..." - echo "" - info_text "Matches: " - data=$(cat "$fname") - [[ "$data" =~ $regex ]] - token=$(echo "${BASH_REMATCH[1]}") - echo "$token" - clipboard "$token" - else - error_text "File does not exist" - fi - fi - else - info_text "Enter the regex you would like to search for:" - read -r regex - info_text "Enter the filename you would like to search:" - read -r fname - if [ -f "$fname" ]; then - info_text "Searching for $regex in $fname..." - grep -c "$regex" "$fname" - else - error_text "File does not exist" - fi - fi - -# ENCRYPTION - -elif [ "$1" = "encrypt" ]; then - info_text "Encrypting $2..." - if arggt "1"; then - if [ -d "$2" ]; then - tar -cvf "$2.tar" "$2" - gpg -c "$2.tar" - rm "$2.tar" - info_text "$2.tar.gpg file created successfully!" - - elif [ -f "$2" ]; then - gpg -c "$2" - info_text "$2.gpg file created successfully!" - - else - error_text "File path provided does not exist. Please try again" - fi - else - info_text "Enter the file/directory you would like to encrypt:" - read -r filepath - - if [ -d "$filepath" ]; then - tar -cvf "$filepath.tar" "$filepath" - gpg -c "$filepath.tar" - rm "$filepath.tar" - info_text "$filepath.tar.gpg file created successfully!" - - elif [ -f "$filepath" ]; then - gpg -c "$filepath" - info_text "$filepath.gpg file created successfully!" - - else - error_text "File path provided does not exist. Please try again" - fi - fi - -elif [ "$1" = "decrypt" ]; then - info_text "Decrypting $2..." - if arggt "1"; then - if [ -f "$2" ]; then - gpg -d "$2" - info_text "$2 file decrypted successfully!" - else - error_text "File path provided does not exist. Please try again" - fi - else - info_text "Enter the file you would like to decrypt: (must have a .gpg extension)" - read -r filepath - if [ -f "$filepath" ]; then - gpg -d "$filepath" - info_text "$filepath file decrypted successfully!" - else - error_text "File path provided does not exist. Please try again" - fi - fi - -# MISC UTILITIES - -elif [ "$1" = "weather" ]; then - if arggt "1"; then - city="$2" - info_text "Getting weather for $city..." - curl wttr.in/"$city" - else - info_text "Getting weather for your current location..." - curl wttr.in - fi - -elif [ "$1" = "moon" ]; then - info_text "Getting moon phase..." - curl wttr.in/moon - -elif [ "$1" = "leap-year" ]; then - if [[ "$year" =~ ^[0-9]*00$ ]]; then - if [ "$((year % 400))" -eq 0 ]; then - info_text "$year is a leap year" - else - info_text "$year is not a leap year" - fi - elif [ "$((year % 4))" -eq 0 ]; then - info_text "$year is a leap year" - else - info_text "$year is not a leap year" - fi - next_one=$((year + 4 - (year % 4))) - info_text "The next leap year is $next_one" - -# WEB UTILITIES - -elif [ "$1" = "webtext" ]; then - if arggt "1"; then - webtext "$2" - else - info_text "Enter the webpage you would like to parse:" - read -r webpage - webtext "$webpage" - fi - -# HELP UTILITIES - -elif [ "$1" = "explain" ]; then - if arggt "1"; then - cmd="$2" - info_text "Finding explanation for $cmd..." - cmd="${cmd// /+}" - openurl "https://explainshell.com/explain?cmd=$cmd" - else - info_text "Enter the command you would like to explain:" - read -r cmd - info_text "Finding explanation for $cmd..." - cmd="${cmd// /+}" - openurl "https://explainshell.com/explain?cmd=$cmd" - fi - -elif [ "$1" = "ask-gpt" ]; then - python3 "${scriptdir}/services/openai_service.py" "conversate" - -elif [ "$1" = "google" ]; then - if arggt "1"; then - openurl "https://www.google.com/search?q=$2" - else - prompt_text "\nEnter your Google search query:" - read -r query - openurl "https://www.google.com/search?q=$query" - fi - echo "" - -# UPDATE - -elif [ "$1" = "update" ]; then - cd "$mydir" || error_text "Failed to execute 'cd $mydir'..." && exit - git pull origin master - cd - || error_text "Failed to execute 'cd -'..." && exit - -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" = "keystore" ]; then - if arggt "1"; then - if arggt "2"; then - check_keystore "$2" "$3" - else - check_keystore "$2" - fi - else - read -rp "${GREEN}Enter the key you would like to add to your keystore:${RESET} " key - check_keystore "$key" - fi - info_text "You're done!" +else + source $(dirname ${BASH_SOURCE[0]})/src/classes/cmd/cmd.h + # Parse input into command object and run it (if valid) + cmd inputCommand + inputCommand.id '=' "$1" + inputCommand_path="${WIX_DIR}/src/commands/$(inputCommand.path).sh" -elif [ "$1" = "setup" ]; then - if [ "$2" = "openai_key" ]; then - info_text "Setting up OpenAI key..." - echo "" - check_keystore "OPENAI_API_KEY" - info_text "You're done!" + if [ -f "${inputCommand_path}" ]; then + # Valid command found - run it + source "${inputCommand_path}" "${@:2}" - elif [ "$2" = "smart_commit" ]; then - info_text "Setting up smart commit..." - echo "" - check_keystore "OPENAI_API_KEY" - check_keystore "USE_SMART_COMMIT" "true" - info_text "You're done!" - else - error_text "Invalid setup command! Try again" + # Invalid command - show error message + sys.error "Invalid command! Try again" echo "Type 'wix' to see the list of available commands (and their arguments), or 'wix help' to be redirected to more in-depth online documentation" fi - -# COMMAND INFO IMAGE OUTPUT - FOR GITHUB ACTIONS WORKFLOW - -elif [ "$1" = "img_stdout" ]; then - output=$(command_info | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g") - output="\$ wix\n\n$output\n" - - convert -background "#300A24" -fill white -font "DejaVu-Sans-Mono" -pointsize 18 -border 20x15 -bordercolor "#300A24" label:"$output" .generated/wixcli-output-preview.png - -# ERROR - -else - error_text "Invalid command! Try again" - echo "Type 'wix' to see the list of available commands (and their arguments), or 'wix help' to be redirected to more in-depth online documentation" fi diff --git a/setup.sh b/setup.sh index 896ba98..41e2981 100755 --- a/setup.sh +++ b/setup.sh @@ -1,32 +1,9 @@ #!/bin/bash -mydir=$(dirname "$mypath") -source "$mydir/functions.sh" - -# COLORS # -GREEN=$(tput setaf 2) -ORANGE=$(tput setaf 3) -RED=$(tput setaf 1) -BLUE=$(tput setaf 4) -CYAN=$(tput setaf 6) -BLACK=$(tput setaf 0) -RESET=$(tput setaf 7) - -# FUNCTIONS -info_text() { - echo "${GREEN}$1${RESET}" -} - -h1_text() { - echo "${BLUE}$1${RESET}" -} - -warn_text() { - echo "${ORANGE}$1${RESET}" -} +source $(dirname ${BASH_SOURCE[0]})/src/classes/sys/sys.h setup_alias() { - envfile=$(envfile) + envfile=$(sys.envfile) { echo ""; echo "# WIX CLI"; echo "alias wix=\"source $(pwd)/wix-cli.sh\""; } >> "$envfile" source "$envfile" } @@ -37,24 +14,24 @@ setup_completion() { } # INITIAL SETUP -if ! using_zsh; then - info_text "Installing dependencies..." - sudo apt-get install xclip +if ! sys.using_zsh; then + sys.info "Installing dependencies..." + sudo apt-get install xclip csvkit 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..." +if sys.mac; then + sys.info "Installing dependencies..." brew install xclip jq brew tap teamookla/speedtest brew install speedtest --force fi -info_text "Installing python dependencies..." +sys.info "Installing python dependencies..." pip3 install -r requirements.txt -info_text "Setting up wix-cli..." +sys.info "Setting up wix-cli..." chmod +x wix-cli.sh @@ -67,7 +44,7 @@ for i in "${files[@]}"; do touch "$md_dir/$i" chmod +rwx "$md_dir/$i" else - warn_text "File $i already exists. Would you like to overwrite it? [ y / n ]" + sys.warn "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" @@ -83,17 +60,17 @@ fi # GET USER SPECIFIC DETAILS echo "" -h1_text "Please enter your github username:" +sys.h1 "Please enter your github username:" read -r gituser echo "username=$gituser" >> $md_dir/git-user.txt echo "" -h1_text "Please enter your full name (this will be used for copyright clauses on GitHub software licenses):" +sys.h1 "Please enter your full name (this will be used for copyright clauses on GitHub software licenses):" read -r fullname echo "name=$fullname" >> $md_dir/git-user.txt echo "" -h1_text "Please enter the default github organization you want to setup with this cli: (enter it's github username) ***leave empty if none***" +sys.h1 "Please enter the default github organization you want to setup with this cli: (enter it's github username) ***leave empty if none***" read -r gitorg if [ "$gitorg" != "" ]; then echo "default=$gitorg" >> $md_dir/git-orgs.txt @@ -103,7 +80,7 @@ echo "" echo "The default directory aliases setup are as follows:" echo "1) docs = ~/Documents" echo "2) down = ~/Downloads" -h1_text "Would you like to include these? [ y / n ]" +sys.h1 "Would you like to include these? [ y / n ]" read -r keep_default_diraliases if [ "$keep_default_diraliases" = "y" ]; then { echo "docs=~/Documents"; echo "down=~/Downloads"; } >> $md_dir/dir-aliases.txt @@ -111,12 +88,12 @@ fi # FINAL SETUP echo "" -info_text "Okay we should be good to go!" +sys.info "Okay we should be good to go!" # ADD ALIAS TO ENV FILE envfile=$(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 ]" + sys.warn "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}" @@ -131,7 +108,7 @@ completionfile="$HOME/.bash_completion" if [ -f "$completionfile" ]; then completion_search=$(cat "$completionfile" | grep -c "$(pwd)/completion.sh") if [ "$completion_search" != "" ]; then - warn_text "It looks like you already have wix completion setup. Would you like to overwrite it? [ y / n ]" + sys.warn "It looks like you already have wix completion setup. Would you like to overwrite it? [ y / n ]" read -r overwrite_completion if [ "$overwrite_completion" = "y" ]; then echo "${ORANGE}Please edit the $HOME/.bashrc file manually to remove your old completion${RESET}" @@ -141,18 +118,18 @@ if [ -f "$completionfile" ]; then setup_completion fi else - warn_text "It looks like you don't have a $HOME/.bash_completion file (allowing you to use the wix command with tab-completion)." - warn_text "Would you like to create one? [ y / n ]" + sys.warn "It looks like you don't have a $HOME/.bash_completion file (allowing you to use the wix command with tab-completion)." + sys.warn "Would you like to create one? [ y / n ]" read -r create_completion if [ "$create_completion" = "y" ]; then touch "$HOME/.bash_completion" setup_completion else - error_text "You need to have a $HOME/.bash_completion file to use wix completion, rerun this setup script if you would like to create one." + sys.error "You need to have a $HOME/.bash_completion file to use wix completion, rerun this setup script if you would like to create one." fi fi echo "" -info_text "WIX CLI successfully added to $envfile !" -info_text "Use 'wix' to get going :)" +sys.info "WIX CLI successfully added to $envfile !" +sys.info "Use 'wix' to get going :)" echo "" \ No newline at end of file diff --git a/src/classes/cmd/cmd.class b/src/classes/cmd/cmd.class new file mode 100644 index 0000000..757aa49 --- /dev/null +++ b/src/classes/cmd/cmd.class @@ -0,0 +1,50 @@ +#!/bin/bash + +# Class named "cmd" for bash Object Oriented Programming (OOP) +. "${WIX_DIR}/src/classes/lib/lib.h" + +lib lib + +# property +cmd_properties=() + +# properties IDs +id=0 + +cmd.sayHello(){ + echo Hello +} + +cmd.property(){ + if [ "$2" == "=" ] + then + cmd_properties[$1]=$3 + else + echo "${cmd_properties[$1]}" + fi +} + +cmd.id(){ + if [ "$1" == "=" ] + then + cmd.property id = "$2" + else + cmd.property id + fi +} + +cmd.name(){ + lib.csv.name "$(cmd.id '')" +} + +cmd.path(){ + lib.csv.path "$(cmd.id '')" +} + +cmd.public(){ + lib.csv.public "$(cmd.id '')" +} + +cmd.args(){ + lib.csv.args "$(cmd.id '')" +} \ No newline at end of file diff --git a/src/classes/cmd/cmd.h b/src/classes/cmd/cmd.h new file mode 100644 index 0000000..de8bdb9 --- /dev/null +++ b/src/classes/cmd/cmd.h @@ -0,0 +1,3 @@ +cmd(){ + . <(sed "s/cmd/$1/g" $(dirname ${BASH_SOURCE[0]})/cmd.class) +} \ No newline at end of file diff --git a/src/classes/lib/lib.class b/src/classes/lib/lib.class new file mode 100644 index 0000000..6273018 --- /dev/null +++ b/src/classes/lib/lib.class @@ -0,0 +1,32 @@ +#!/bin/bash + +csv_file="${WIX_DIR}/src/data/arg_scripts.csv" + +lib.csv.all(){ + lines=$(csvsql --query "select * from arg_scripts where id='$1'" "${csv_file}") + echo "$lines" +} + +lib.csv.name(){ + lines=$(csvsql --query "select name from arg_scripts where id='$1'" "${csv_file}") + lines_array=($lines) + echo "${lines_array[1]}" +} + +lib.csv.path(){ + lines=$(csvsql --query "select path from arg_scripts where id='$1'" "${csv_file}") + lines_array=($lines) + echo "${lines_array[1]}" +} + +lib.csv.public(){ + lines=$(csvsql --query "select public from arg_scripts where id='$1'" "${csv_file}") + lines_array=($lines) + echo "${lines_array[1]}" +} + +lib.csv.args(){ + lines=$(csvsql --query "select args from arg_scripts where id='$1'" "${csv_file}") + lines_array=($lines) + echo "${lines_array[1]}" +} \ No newline at end of file diff --git a/src/classes/lib/lib.h b/src/classes/lib/lib.h new file mode 100644 index 0000000..da89f93 --- /dev/null +++ b/src/classes/lib/lib.h @@ -0,0 +1,3 @@ +lib(){ + . <(sed "s/lib/$1/g" $(dirname ${BASH_SOURCE[0]})/lib.class) +} \ No newline at end of file diff --git a/functions.sh b/src/classes/sys/sys.class similarity index 50% rename from functions.sh rename to src/classes/sys/sys.class index 40337e3..a27c3a7 100644 --- a/functions.sh +++ b/src/classes/sys/sys.class @@ -9,30 +9,27 @@ CYAN=$(tput setaf 6) BLACK=$(tput setaf 0) RESET=$(tput setaf 7) -# FILE EXTs -export exts=("sh" "txt" "py") - # CONST STRING PROMPTS export notsupported="${RED}This path is not supported${RESET}" # PROMPTS -info_text() { +sys.info() { echo "${GREEN}$1${RESET}" } -h1_text() { +sys.h1() { echo "${BLUE}$1${RESET}" } -h2_text() { +sys.h2() { echo "${CYAN}$1${RESET}" } -warn_text() { +sys.warn() { echo "${ORANGE}$1${RESET}" } -error_text() { +sys.error() { if [ "$1" = "" ]; then echo "$notsupported" else @@ -41,7 +38,7 @@ error_text() { } # VALIDATION -empty() { +sys.empty() { if [ "$1" = "" ]; then return 0 else @@ -50,7 +47,7 @@ empty() { } # MAC & LINUX FUNCTIONS -using_zsh() { +sys.using_zsh() { if [[ "$(ps -o args= -p $$)" = *"zsh"* ]]; then return 0 else @@ -58,8 +55,8 @@ using_zsh() { fi } -openurl() { - if using_zsh; then +sys.openurl() { + if sys.using_zsh; then open "$1" else { @@ -68,8 +65,8 @@ openurl() { fi } -envfile() { - if using_zsh; then +sys.envfile() { + if sys.using_zsh; then echo "$HOME/.zshrc" else echo "$HOME/.bashrc" @@ -77,8 +74,8 @@ envfile() { return 0 } -arm() { - if using_zsh; then +sys.arm() { + if sys.using_zsh; then if [[ "$(sysctl -n sysctl.proc_translated)" == "1" ]] || [[ "$(uname -m)" == "arm64" ]]; then return 0; else @@ -89,14 +86,62 @@ arm() { fi } -openfile() { +sys.openfile() { xdg-open "file:///$1" } -mac() { +sys.mac() { if [[ "$OSTYPE" == "darwin"* ]]; then return 0 else return 1 fi +} + +sys.linux() { + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + return 0 + else + return 1 + fi +} + +sys.windows() { + if [[ "$OSTYPE" == "msys" ]]; then + return 0 + else + return 1 + fi +} + +sys.wsl() { + if [[ "$(uname -r)" == *"Microsoft"* ]]; then + return 0 + else + return 1 + fi +} + +sys.webtext() { + lynx -dump -cookies "$1" +} + +sys.clipboard() { + if command -v pbcopy >/dev/null 2>&1; then + sys.info "This has been saved to your clipboard!" + echo "$1" | pbcopy + elif command -v xclip >/dev/null 2>&1; then + sys.info "This has been saved to your clipboard!" + echo "$1" | xclip -selection c + else + sys.warn "Clipboard not supported on this system, please install xclip or pbcopy." + fi +} + +sys.editfile() { + if sys.using_zsh; then + vi "$1" + else + gedit "$1" + fi } \ No newline at end of file diff --git a/src/classes/sys/sys.h b/src/classes/sys/sys.h new file mode 100644 index 0000000..794de10 --- /dev/null +++ b/src/classes/sys/sys.h @@ -0,0 +1,3 @@ +sys(){ + . <(sed "s/sys/$1/g" $(dirname ${BASH_SOURCE[0]})/sys.class) +} \ No newline at end of file diff --git a/src/classes/wgit/wgit.class b/src/classes/wgit/wgit.class new file mode 100644 index 0000000..82d92f2 --- /dev/null +++ b/src/classes/wgit/wgit.class @@ -0,0 +1,140 @@ +#!/bin/bash + +. "${WIX_DIR}/src/classes/sys/sys.h" +sys sys + +wgit.is_git_repo(){ + if git rev-parse --git-dir > /dev/null 2>&1; then + branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p') + fi + if ! sys.empty "$branch" ; then + return 0 + else + sys.error "This is not a git repository..." + return 1 + fi +} + +wgit.giturl(){ + if wgit.is_git_repo ; then + sys.openurl "$1" + fi +} + +wgit.ginit(){ + git init + if sys.empty "$2" ; then + sys.info "Provide a name for this repository:" + read -r rname + echo "# $rname" >> README.md + sys.info "Would you like to add a MIT license to this repository? [ Yy / Nn ]" + read -r rlicense + if [ "$rlicense" = "y" ] || [ "$rlicense" = "Y" ] + then + touch "LICENSE.md" + echo -e "MIT License\n\nCopyright (c) $(wixd.user.name) $year\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE." >> "LICENSE.md" + fi + wgit.commit "wix-cli: first commit" + git remote add origin "git@github.com:$1/$rname.git" + sys.openurl "https://github.com/$3" + else + echo "# $2" >> README.md + wgit.commit "wix-cli: first commit" + git remote add origin "git@github.com:$1/$2.git" + sys.openurl "https://github.com/$3" + fi +} + +wgit.wix_ginit(){ + if ! sys.empty "$1"; then + mkdir "$1" + cd "$1" || return 1 + fi + + if sys.empty "$branch" ; then + sys.info "Would you like you to host this repository under a GitHub organization? [ Yy / Nn ]" + read -r response + if [ "$response" = "y" ] || [ "$response" = "Y" ] + then + echo "" + sys.h1 "Your saved GitHub organization aliases:" + wixd.orgs + echo "" + sys.info "Please enter the organization name alias you would like to use:" + read -r orgalias + if wixd.orgexists "$orgalias" ; then + wgit.ginit "$(wixd.org $orgalias)" "$2" "organizations/$(wixd.org $orgalias)/repositories/new" + else + wgit.ginit "$(wixd.user.username)" "$2" "new" + fi + else + wgit.ginit "$(wixd.user.username)" "$2" "new" + fi + else + sys.error "This is already a git repository..." + fi +} + +wgit.commit() { + git add . + if sys.empty "$1" ; then + if [ -f "${WIX_DATA_DIR}/.env" ]; then + if grep -q "OPENAI_API_KEY=" "${WIX_DATA_DIR}/.env" && grep -q "USE_SMART_COMMIT=true" "${WIX_DATA_DIR}/.env" ; then + IFS=$'\n' lines=($(python3 "$WIX_SCRIPT_DIR/services/openai_service.py" "smart")) + sys.h2 "GPT-3 Suggestion" + if sys.using_zsh; then + sys.h2 "Title:${RESET} ${lines[1]}" + sys.h2 "Description:${RESET} ${lines[2]}" + echo "" + sys.info "Press enter to use this suggestion or type your own description." + read -r description + git commit -m "${description:-${lines[1]}}" -m "${lines[2]}" + else + sys.h2 "Title:${RESET} ${lines[0]}" + sys.h2 "Description:${RESET} ${lines[1]}" + echo "" + sys.info "Press enter to use this suggestion or type your own description." + read -r description + git commit -m "${description:-${lines[0]}}" -m "${lines[1]}" + fi + else + sys.info "Provide a commit description: (defaults to 'wix-cli quick commit')" + read -r description + git commit -m "${description:-wix-cli quick commit}" + fi + else + sys.info "Provide a commit description: (defaults to 'wix-cli quick commit')" + read -r description + git commit -m "${description:-wix-cli quick commit}" + fi + else + git commit -m "${1:-wix-cli quick commit}" + fi +} + +wgit.push() { + if [ "$1" != "$branch" ]; then + git checkout "$1" + fi + wgit.commit "$2" + git push origin "$1" +} + +wgit.npush() { + git checkout -b "$1" + wgit.commit "$2" + git push origin "$1" +} + +wgit.pull() { + if [ "$1" != "$branch" ]; then + git checkout "$1" + fi + git pull origin "$1" +} + +wgit.bpr() { + wgit.npush "$1" + sys.info "Creating PR for $branch in $repo_url..." + sys.openurl "https://github.com/$repo_url/pull/new/$1" +} \ No newline at end of file diff --git a/src/classes/wgit/wgit.h b/src/classes/wgit/wgit.h new file mode 100644 index 0000000..38fa6a9 --- /dev/null +++ b/src/classes/wgit/wgit.h @@ -0,0 +1,3 @@ +wgit(){ + . <(sed "s/wgit/$1/g" $(dirname ${BASH_SOURCE[0]})/wgit.class) +} \ No newline at end of file diff --git a/src/classes/wixd/wixd.class b/src/classes/wixd/wixd.class new file mode 100644 index 0000000..b767be2 --- /dev/null +++ b/src/classes/wixd/wixd.class @@ -0,0 +1,387 @@ +#!/bin/bash + +# -- WIXD CLASS -- + +# ==================================== +# -- INPUTS -- +# ==================================== + +wixd.arggt() { + if [ "$num_args" -gt "$1" ]; then + return 0 + else + return 1 + fi +} + +# ==================================== +# -- DATA -- +# ==================================== + +# User + +wixd.user.username() { + declare -A user + declare -a user_lines user_lines=() + while IFS='' read -r line || [[ -n "$line" ]]; do + user_lines+=("$line") + done < "$WIX_DATA_DIR/git-user.txt" + for line in "${user_lines[@]}"; do + key=${line%%=*} + value=${line#*=} + user[$key]=$value + done + + echo "${user[username]}" +} + +wixd.user.name() { + declare -A user + declare -a user_lines user_lines=() + while IFS='' read -r line || [[ -n "$line" ]]; do + user_lines+=("$line") + done < "$WIX_DATA_DIR/git-user.txt" + for line in "${user_lines[@]}"; do + key=${line%%=*} + value=${line#*=} + user[$key]=$value + done + + echo "${user[name]}" +} + +# Directories + +wixd.direxists() { + declare -A mydirs + declare -a dir_lines dir_lines=() + while IFS='' read -r line || [[ -n "$line" ]]; do + dir_lines+=("$line") + done < "$WIX_DATA_DIR/dir-aliases.txt" + for line in "${dir_lines[@]}"; do + key=${line%%=*} + value=${line#*=} + mydirs[$key]=$value + done + + if [[ -v mydirs["$1"] ]]; then + return 0 + else + return 1 + fi +} + +wixd.dir() { + declare -A mydirs + declare -a dir_lines dir_lines=() + while IFS='' read -r line || [[ -n "$line" ]]; do + dir_lines+=("$line") + done < "$WIX_DATA_DIR/dir-aliases.txt" + for line in "${dir_lines[@]}"; do + key=${line%%=*} + value=${line#*=} + mydirs[$key]=$value + done + + echo "${mydirs[$1]}" +} + +# Organizations + +wixd.org() { + declare -A myorgs + declare -a org_lines org_lines=() + while IFS='' read -r line || [[ -n "$line" ]]; do + org_lines+=("$line") + done < "$WIX_DATA_DIR/git-orgs.txt" + for line in "${org_lines[@]}"; do + key=${line%%=*} + value=${line#*=} + myorgs[$key]=$value + done + + echo "${myorgs[$1]}" +} + +wixd.orgs() { + # declare -A myorgs + declare -a org_lines org_lines=() + while IFS='' read -r line || [[ -n "$line" ]]; do + org_lines+=("$line") + done < "$WIX_DATA_DIR/git-orgs.txt" + for line in "${org_lines[@]}"; do + key=${line%%=*} + value=${line#*=} + # myorgs[$key]=$value + echo "${key}: ${value}" + done +} + +wixd.orgexists() { + declare -A myorgs + declare -a org_lines org_lines=() + while IFS='' read -r line || [[ -n "$line" ]]; do + org_lines+=("$line") + done < "$WIX_DATA_DIR/git-orgs.txt" + for line in "${org_lines[@]}"; do + key=${line%%=*} + value=${line#*=} + myorgs[$key]=$value + done + + if [[ -v myorgs[$1] ]]; then + return 0 + else + return 1 + fi +} + +# Scripts + +wixd.scriptexists(){ + declare -A myscripts + declare -a script_lines script_lines=() + while IFS='' read -r line || [[ -n "$line" ]]; do + script_lines+=("$line") + done < "$WIX_DATA_DIR/run-configs.txt" + for line in "${script_lines[@]}"; do + key=${line%%=*} + value=${line#*=} + myscripts[$key]=$value + done + + if [[ -v myscripts[$1] ]]; then + return 0 + else + return 1 + fi +} + +# Keystore + +wixd.check_keystore() { + envfile="$WIX_DATA_DIR/.env" + if [[ -f "$envfile" ]]; then + # Check if key-value pair exists in .env file + if grep -q "^$1=" "$envfile"; then + # Prompt user to replace the existing value + read -rp "${GREEN}Key \"$1\" already exists. Do you want to replace the value? (y/n):${RESET} " choice + if [[ $choice == "y" || $choice == "Y" ]]; then + if [ -n "$2" ]; then + # Replace the value in .env + sed -i "s/^$1=.*/$1=$2/" "$envfile" + sys.info "Value for key \"$1\" replaced successfully!" + else + # Prompt user to enter the value + read -rp "${GREEN}Enter the value for \"$1\":${RESET} " value + + # Replace the value in .env + sed -i "s/^$1=.*/$1=$value/" "$envfile" + sys.info "Value for key \"$1\" replaced successfully!" + fi + else + sys.info "Value for key \"$1\" not replaced." + fi + else + if [ -n "$2" ]; then + # Append key-value pair to .env + echo -e "\n$1=$2" >> "$envfile" + sys.info "Value for key \"$1\" appended successfully!" + else + # Prompt user to enter the value + read -rp "${GREEN}Enter the value for \"$1\":${RESET} " value + + # Append key-value pair to .env + echo -e "\n$1=$value" >> "$envfile" + sys.info "Value for key \"$1\" appended successfully!" + fi + fi + else + if [ -n "$2" ]; then + # Create .env file and add the key-value pair + echo "$1=$2" > "$envfile" + sys.info ".env file created successfully!" + sys.info "Value for key \"$1\" appended successfully!" + else + # Prompt user to enter the value + read -rp "${GREEN}Enter the value for \"$1\":${RESET} " value + + # Create .env file and add the key-value pair + echo "$1=$value" > "$envfile" + sys.info ".env file created successfully!" + sys.info "Value for key \"$1\" appended successfully!" + fi + fi + echo "" +} + +# ==================================== +# -- COMMAND FUNCTIONS -- +# ==================================== + +wixd.cd() { + declare -A mydirs + declare -a dir_lines dir_lines=() + while IFS='' read -r line || [[ -n "$line" ]]; do + dir_lines+=("$line") + done < "$WIX_DATA_DIR/dir-aliases.txt" + for line in "${dir_lines[@]}"; do + key=${line%%=*} + value=${line#*=} + mydirs[$key]=$value + done + if wixd.arggt "1" ; then + if [[ -v mydirs["$1"] ]]; then + alias_dest="${mydirs[$1]}" + destination="${alias_dest/~/${HOME}}" + if ! sys.empty "$2" ; then + destination="${alias_dest/~/${HOME}}/$2" + fi + sys.info "Travelling to -> $destination" + eval cd "$destination" || (sys.error "The path $destination does not exist" && return 1) + return 0 + else + sys.error + return 1 + fi + else + sys.info "Where do you want to go?" + read -r dir + if [[ -v mydirs[$dir] ]]; then + alias_dest="${mydirs[$dir]}" + destination="${alias_dest/~/${HOME}}" + sys.info "Travelling to -> $destination" + eval cd "$destination" || (sys.error "The path $destination does not exist" && return 1) + return 0 + else + sys.error + return 1 + fi + fi +} + +wixd.run() { + declare -A myscripts + declare -a script_lines script_lines=() + while IFS='' read -r line || [[ -n "$line" ]]; do + script_lines+=("$line") + done < "$WIX_DATA_DIR/run-configs.txt" + for line in "${script_lines[@]}"; do + key=${line%%=*} + value=${line#*=} + myscripts[$key]=$value + done + + if [[ -v myscripts[$1] ]]; then + sys.info "Running $1 script!" + source "$WIX_DATA_DIR/run-configs/${myscripts[$1]}.sh" + else + sys.error "This script does not exist... Please try again" + fi +} + +# ==================================== +# -- INFO FUNCTIONS -- +# ==================================== + + +wixd.command_info() { + echo "Welcome to the..." + echo "" + sys.info " ${CYAN}Y${BLUE}8b ${CYAN}Y${BLUE}8b ${CYAN}Y${BLUE}888P ${CYAN}8${BLUE}88 ${CYAN}Y${BLUE}8b Y8P${GREEN} e88'Y88 888 888 " + sys.info " ${CYAN}Y${BLUE}8b ${CYAN}Y${BLUE}8b ${CYAN}Y${BLUE}8P ${CYAN}8${BLUE}88 ${CYAN}Y${BLUE}8b Y${GREEN} d888 'Y 888 888 " + sys.info " ${CYAN}Y${BLUE}8b ${CYAN}Y${BLUE}8b ${CYAN}Y${BLUE} ${CYAN}8${BLUE}88 ${CYAN}Y${BLUE}8b${GREEN} C8888 888 888 " + sys.info " ${CYAN}Y${BLUE}8b ${CYAN}Y${BLUE}8b ${CYAN}8${BLUE}88 e ${CYAN}Y${BLUE}8b${GREEN} Y888 ,d 888 ,d 888 " + sys.info " ${CYAN}Y${BLUE}8P ${CYAN}Y${BLUE} ${CYAN}8${BLUE}88 d8b ${CYAN}Y${BLUE}8b${GREEN} \"88,d88 888,d88 888 " + echo "" + echo "v$version" + echo "" + sys.h1 "MAINTENANCE:" + echo "- sys-info ${ORANGE}: view shell info${RESET}" + echo "- install-deps ${ORANGE}: install dependencies${RESET}" + echo "" + sys.h1 "DIRECTORY NAVIGATION:" + echo "- cd ${ORANGE}: navigation${RESET}" + echo "- back ${ORANGE}: return to last dir${RESET}" + echo "" + sys.h1 "CODE:" + echo "- vsc ${ORANGE}: open directory in Visual Studio Code${RESET}" + echo "- run ${ORANGE}: setup and run environment${RESET}" + echo "" + sys.h1 "GITHUB AUTOMATION:" + echo "- push ${ORANGE}: push changes to repo branch${RESET}" + echo "- pull ${ORANGE}: pull changes from repo branch${RESET}" + echo "- ginit ${ORANGE}: setup git repo in existing/new directory${RESET}" + echo "- nb ${ORANGE}: create new branch${RESET}" + echo "- pr ${ORANGE}: create PR for branch${RESET}" + echo "- bpr ${ORANGE}: checkout changes to new branch and create PR${RESET}" + echo "- commits ${ORANGE}: view commit history${RESET}" + echo "- lastcommit ${ORANGE}: view last commit${RESET}" + echo "- setup smart_commit ${ORANGE}: setup smart commit${RESET}" + echo "" + sys.h1 "URLS:" + echo "- repo ${ORANGE}: go to git repo URL${RESET}" + echo "- branch ${ORANGE}: go to git branch URL${RESET}" + echo "- prs ${ORANGE}: go to git repo Pull Requests URL${RESET}" + echo "- actions ${ORANGE}: go to git repo Actions URL${RESET}" + echo "- issues ${ORANGE}: go to git repo Issues URL${RESET}" + echo "- notifs ${ORANGE}: go to git notifications URL${RESET}" + echo "- profile ${ORANGE}: go to git profile URL${RESET}" + echo "- org ${ORANGE}: go to git org URL${RESET}" + echo "- help ${ORANGE}: go to wix-cli GitHub Pages URL${RESET}" + echo "" + sys.h1 "MY DATA:" + echo "- user ${ORANGE}: view your user-specific data (ie. name, GitHub username)${RESET}" + echo "- myorgs ${ORANGE}: view your GitHub organizations and their aliases${RESET}" + echo "- mydirs ${ORANGE}: view your directory aliases${RESET}" + echo "- myscripts ${ORANGE}: view your script aliases${RESET}" + echo "- todo ${ORANGE}: view your to-do list${RESET}" + echo "" + sys.h1 "MANAGE MY DATA:" + echo "- editd ${ORANGE}: edit a piece of your data (ie. user, myorgs, mydirs, myscripts, todo)${RESET}" + echo "- edits ${ORANGE}: edit a script (you must use an alias present in myscripts)${RESET}" + echo "- newscript ${ORANGE}: create a new script${RESET}" + echo "" + sys.h1 "ENV/KEYSTORE:" + echo "- keystore ${ORANGE}: add a key-value pair to your keystore${RESET}" + echo "- setup openai_key ${ORANGE}: setup your OpenAI API key${RESET}" + echo "- setup smart_commit ${ORANGE}: setup your smart commit${RESET}" + echo "" + sys.h1 "FILE UTILITIES:" + echo "- fopen ${ORANGE}: open current directory in files application${RESET}" + echo "- find \"\" ${ORANGE}: find a file inside the current directory using regex${RESET}" + echo "- encrypt ${ORANGE}: GPG encrypt a file/directory (saves as a new .gpg file)${RESET}" + echo "- decrypt ${ORANGE}: GPG decrypt a file (must be a .gpg file)${RESET}" + echo "" + sys.h1 "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 "" + sys.h1 "IMAGE UTILITIES:" + echo "- genqr ${ORANGE}: generate a png QR code for the specified URL${RESET}" + echo "- upscale ${ORANGE}: upscale an image's resolution (**does not smooth interpolated pixels**)${RESET}" + echo "" + sys.h1 "TEXT UTILITIES:" + echo "- genpass ${ORANGE}: generate and copy random password string (of default length 16)${RESET}" + echo "- genhex ${ORANGE}: generate and copy random hex string (of default length 32)${RESET}" + echo "- genb64 ${ORANGE}: generate and copy random base64 string (of default length 32)${RESET}" + echo "- copy ${ORANGE}: copy a string or the output of a shell command (using \$() syntax) to your clipboard${RESET}" + echo "- lastcmd ${ORANGE}: copy the last command you ran to your clipboard${RESET}" + echo "" + sys.h1 "WEB UTILITIES:" + echo "- webtext ${ORANGE}: extract readable text from a website" + echo "" + sys.h1 "MISC UTILITIES:" + echo "- weather ${ORANGE}: get the weather forecast for your current location${RESET}" + echo "- moon ${ORANGE}: get the current moon phase${RESET}" + echo "- leap-year ${ORANGE}: tells you the next leap year" + echo "" + sys.h1 "HELP UTILITIES:" + echo "- explain \"\" ${ORANGE}: explain the syntax of the input bash command${RESET}" + echo "- ask-gpt ${ORANGE}: start a conversation with OpenAI's ChatGPT in the terminal${RESET}" + echo "- google \"\" ${ORANGE}: google a query${RESET}" + echo "" +} diff --git a/src/classes/wixd/wixd.h b/src/classes/wixd/wixd.h new file mode 100644 index 0000000..642ac24 --- /dev/null +++ b/src/classes/wixd/wixd.h @@ -0,0 +1,3 @@ +wixd(){ + . <(sed "s/wixd/$1/g" $(dirname ${BASH_SOURCE[0]})/wixd.class) +} \ No newline at end of file diff --git a/src/commands/actions.sh b/src/commands/actions.sh new file mode 100644 index 0000000..dc2eba0 --- /dev/null +++ b/src/commands/actions.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +sys.info "Redirecting to Action Workflows on $repo_url..." +wgit.giturl "https://github.com/$repo_url/actions" diff --git a/src/commands/ask-gpt.sh b/src/commands/ask-gpt.sh new file mode 100644 index 0000000..5e691b8 --- /dev/null +++ b/src/commands/ask-gpt.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +python3 "${WIX_DIR}/src/commands/scripts/services/openai_service.py" "conversate" \ No newline at end of file diff --git a/src/commands/back.sh b/src/commands/back.sh new file mode 100644 index 0000000..dc45207 --- /dev/null +++ b/src/commands/back.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +cd - || sys.error "Failed to execute 'cd -'..." \ No newline at end of file diff --git a/src/commands/bpr.sh b/src/commands/bpr.sh new file mode 100644 index 0000000..8d36a38 --- /dev/null +++ b/src/commands/bpr.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +if wgit.is_git_repo ; then + if wixd.arggt "1" ; then + wgit.bpr "$@" + else + sys.info "Provide a branch name:" + read -r name + if [ "$name" != "" ]; then + wgit.bpr "$name" + fi + fi +fi \ No newline at end of file diff --git a/src/commands/branch.sh b/src/commands/branch.sh new file mode 100644 index 0000000..28ed24e --- /dev/null +++ b/src/commands/branch.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +sys.info "Redirecting to $branch on $repo_url..." +wgit.giturl "https://github.com/$repo_url/tree/$branch" \ No newline at end of file diff --git a/src/commands/cd.sh b/src/commands/cd.sh new file mode 100644 index 0000000..f9a5746 --- /dev/null +++ b/src/commands/cd.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +wixd.cd "$@" \ No newline at end of file diff --git a/src/commands/commits.sh b/src/commands/commits.sh new file mode 100644 index 0000000..c9b8130 --- /dev/null +++ b/src/commands/commits.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +git log --pretty=format:"${GREEN}%H${RESET} - ${BLUE}%an${RESET}, ${ORANGE}%cr [%cd]${RESET} : %s" \ No newline at end of file diff --git a/src/commands/copy.sh b/src/commands/copy.sh new file mode 100644 index 0000000..0d3f45f --- /dev/null +++ b/src/commands/copy.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +if wixd.arggt "1"; then + if [[ "$1" =~ ^\$\(.*\)$ ]]; then + DATA="$1" + sys.clipboard "$DATA" + else + sys.clipboard "$1" + fi +else + sys.info "Enter the text you would like to copy to your sys.clipboard:" + read -r text + sys.clipboard "$text" +fi \ No newline at end of file diff --git a/src/commands/decrypt.sh b/src/commands/decrypt.sh new file mode 100644 index 0000000..3e63864 --- /dev/null +++ b/src/commands/decrypt.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +sys.info "Decrypting $1..." +if wixd.arggt "1"; then + if [ -f "$1" ]; then + gpg -d "$1" + sys.info "$1 file decrypted successfully!" + else + sys.error "File path provided does not exist. Please try again" + fi +else + sys.info "Enter the file you would like to decrypt: (must have a .gpg extension)" + read -r filepath + if [ -f "$filepath" ]; then + gpg -d "$filepath" + sys.info "$filepath file decrypted successfully!" + else + sys.error "File path provided does not exist. Please try again" + fi +fi \ No newline at end of file diff --git a/src/commands/editd.sh b/src/commands/editd.sh new file mode 100644 index 0000000..b2dc861 --- /dev/null +++ b/src/commands/editd.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +data_to_edit="$1" +if ! wixd.arggt "1"; then + sys.info "What data would you like to edit?" + read -r data_to_edit_prompt + data_to_edit=$data_to_edit_prompt + + declare -a datanames + datanames=( "user" "myorgs" "mydirs" "myscripts" ) + if ! printf '%s\0' "${datanames[@]}" | grep -Fxqz -- "$data_to_edit_prompt"; then + sys.error "'$data_to_edit_prompt' is not a valid piece of data, please try one of the following: ${datanames[*]}" + return 1 + fi +fi +if [ "$data_to_edit" = "user" ]; then + sys.editfile "$WIX_DATA_DIR/git-user.txt" +elif [ "$data_to_edit" = "myorgs" ]; then + sys.editfile "$WIX_DATA_DIR/git-orgs.txt" +elif [ "$data_to_edit" = "mydirs" ]; then + sys.editfile "$WIX_DATA_DIR/dir-aliases.txt" +elif [ "$data_to_edit" = "myscripts" ]; then + sys.editfile "$WIX_DATA_DIR/run-configs.txt" +elif [ "$data_to_edit" = "todo" ]; then + sys.editfile "$WIX_DATA_DIR/todo.txt" +fi \ No newline at end of file diff --git a/src/commands/edits.sh b/src/commands/edits.sh new file mode 100644 index 0000000..4763f7f --- /dev/null +++ b/src/commands/edits.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +script_to_edit="$1" +if ! wixd.arggt "1"; then + sys.info "What script would you like to edit?" + read -r script_to_edit_prompt + script_to_edit=$script_to_edit_prompt +fi +if wixd.scriptexists "$script_to_edit"; then + sys.info "Editing $script_to_edit script..." + sys.editfile "$WIX_DATA_DIR/run-configs/$script_to_edit.sh" +else + sys.error "This script does not exist... Please try again" +fi \ No newline at end of file diff --git a/src/commands/encrypt.sh b/src/commands/encrypt.sh new file mode 100644 index 0000000..eb20ad3 --- /dev/null +++ b/src/commands/encrypt.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +sys.info "Encrypting $1..." +if wixd.arggt "1"; then + if [ -d "$1" ]; then + tar -cvf "$1.tar" "$1" + gpg -c "$1.tar" + rm "$1.tar" + sys.info "$1.tar.gpg file created successfully!" + + elif [ -f "$1" ]; then + gpg -c "$1" + sys.info "$1.gpg file created successfully!" + + else + sys.error "File path provided does not exist. Please try again" + fi +else + sys.info "Enter the file/directory you would like to encrypt:" + read -r filepath + + if [ -d "$filepath" ]; then + tar -cvf "$filepath.tar" "$filepath" + gpg -c "$filepath.tar" + rm "$filepath.tar" + sys.info "$filepath.tar.gpg file created successfully!" + + elif [ -f "$filepath" ]; then + gpg -c "$filepath" + sys.info "$filepath.gpg file created successfully!" + + else + sys.error "File path provided does not exist. Please try again" + fi +fi \ No newline at end of file diff --git a/src/commands/explain.sh b/src/commands/explain.sh new file mode 100644 index 0000000..398fb58 --- /dev/null +++ b/src/commands/explain.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +if wixd.arggt "1"; then + cmd="$1" + sys.info "Finding explanation for $cmd..." + cmd="${cmd// /+}" + sys.openurl "https://explainshell.com/explain?cmd=$cmd" +else + sys.info "Enter the command you would like to explain:" + read -r cmd + sys.info "Finding explanation for $cmd..." + cmd="${cmd// /+}" + sys.openurl "https://explainshell.com/explain?cmd=$cmd" +fi \ No newline at end of file diff --git a/src/commands/find.sh b/src/commands/find.sh new file mode 100644 index 0000000..3fe1bb9 --- /dev/null +++ b/src/commands/find.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +if wixd.arggt "1"; then + # find . -type f -name "$1" + find . -regextype posix-extended -regex ".*$1.*" +else + sys.info "Enter the regex you would like to use:" + read -r regex + # find . -type f -name "$fname" + find . -regextype posix-extended -regex "$regex" +fi diff --git a/src/commands/fopen.sh b/src/commands/fopen.sh new file mode 100644 index 0000000..2877a31 --- /dev/null +++ b/src/commands/fopen.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +if wixd.arggt "1"; then + dir="$1" + if wixd.direxists "$dir"; then + mydir="${mydirs[$dir]/\~/${HOME}}" + sys.info "Opening $WIX_DIR..." + sys.openfile "$WIX_DIR" + else + sys.error "Directory alias does not exist" + fi +else + sys.info "Opening current directory..." + sys.openfile "$(pwd)" +fi \ No newline at end of file diff --git a/src/commands/genb64.sh b/src/commands/genb64.sh new file mode 100644 index 0000000..6ab5282 --- /dev/null +++ b/src/commands/genb64.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +hex_size=32 +if wixd.arggt "1"; then + if ! [[ "$1" =~ ^[0-9]+$ ]]; then + sys.error "Error: the base64-length argument must be an integer" + return 1 + else + hex_size=$1 + fi +fi +pass=$(openssl rand -base64 "$hex_size") +truncated_pass="${pass:0:$hex_size}" +sys.info "Your random base64 string is: ${RESET}$truncated_pass" +sys.clipboard "$truncated_pass" \ No newline at end of file diff --git a/src/commands/genhex.sh b/src/commands/genhex.sh new file mode 100644 index 0000000..c7455b7 --- /dev/null +++ b/src/commands/genhex.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +hex_size=32 +if wixd.arggt "1"; then + if ! [[ "$1" =~ ^[0-9]+$ ]]; then + sys.error "Error: the hex-length argument must be an integer" + return 1 + else + hex_size=$1 + fi +fi +pass=$(openssl rand -hex "$hex_size") +truncated_pass="${pass:0:$hex_size}" +sys.info "Your random hex string is: ${RESET}$truncated_pass" +sys.clipboard "$truncated_pass" \ No newline at end of file diff --git a/src/commands/genpass.sh b/src/commands/genpass.sh new file mode 100644 index 0000000..7287814 --- /dev/null +++ b/src/commands/genpass.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +pass_size=16 +if wixd.arggt "1"; then + if ! [[ "$1" =~ ^[0-9]+$ ]]; then + sys.error "Error: the password-length argument must be an integer" + return 1 + else + pass_size=$1 + fi +fi +pass=$(python3 "${WIX_SCRIPT_DIR}/random_string_gen.py" "$pass_size") +sys.info "Your random password string is: ${RESET}$pass" +sys.clipboard "$pass" \ No newline at end of file diff --git a/src/commands/genqr.sh b/src/commands/genqr.sh new file mode 100644 index 0000000..00efe25 --- /dev/null +++ b/src/commands/genqr.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +link="$1" +fname="$2" +if ! wixd.arggt "1"; then + sys.info "Enter the URL you would like to link to:" + read -r url + link="$url" + + if ! wixd.arggt "2"; then + sys.info "Enter the name for your QR code:" + read -r qrname + fname="$qrname" + fi +fi +sys.info "Generating a QR code..." +qrencode -o "$fname.png" "$link" +display "$fname.png" \ No newline at end of file diff --git a/src/commands/ginit.sh b/src/commands/ginit.sh new file mode 100644 index 0000000..a87d6b0 --- /dev/null +++ b/src/commands/ginit.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +wgit.wix_ginit "${@:2}" \ No newline at end of file diff --git a/src/commands/google.sh b/src/commands/google.sh new file mode 100644 index 0000000..97a61eb --- /dev/null +++ b/src/commands/google.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +if wixd.arggt "1"; then + sys.openurl "https://www.google.com/search?q=$1" +else + prompt_text "\nEnter your Google search query:" + read -r query + sys.openurl "https://www.google.com/search?q=$query" +fi +echo "" \ No newline at end of file diff --git a/src/commands/hardware-ports.sh b/src/commands/hardware-ports.sh new file mode 100644 index 0000000..217d703 --- /dev/null +++ b/src/commands/hardware-ports.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +if sys.mac; then + networksetup -listallhardwareports +else + echo "Not supported on this OS" +fi diff --git a/src/commands/help.sh b/src/commands/help.sh new file mode 100644 index 0000000..c558e80 --- /dev/null +++ b/src/commands/help.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +sys.openurl "https://hwixley.github.io/WIX-CLI/index.html" \ No newline at end of file diff --git a/src/commands/img_stdout.sh b/src/commands/img_stdout.sh new file mode 100644 index 0000000..da2afea --- /dev/null +++ b/src/commands/img_stdout.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# COMMAND INFO IMAGE OUTPUT - FOR GITHUB ACTIONS WORKFLOW + +output=$(command_info | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g") +output="\$ wix\n\n$output\n" + +convert -background "#300A24" -fill white -font "DejaVu-Sans-Mono" -pointsize 18 -border 20x15 -bordercolor "#300A24" label:"$output" "${WIX_DIR}/.generated/wixcli-output-preview.png" \ No newline at end of file diff --git a/src/commands/install-deps.sh b/src/commands/install-deps.sh new file mode 100644 index 0000000..1d46af3 --- /dev/null +++ b/src/commands/install-deps.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +if ! sys.using_zsh; then + sys.info "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 sys.mac; then + sys.info "Installing dependencies..." + brew install xclip jq + brew tap teamookla/speedtest + brew install speedtest --force +fi + +sys.info "Installing python dependencies..." +pip3 install -r requirements.txt diff --git a/src/commands/ip.sh b/src/commands/ip.sh new file mode 100644 index 0000000..de1d59f --- /dev/null +++ b/src/commands/ip.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +echo "" +sys.info "Local IPs:" +if sys.mac; then + ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}' +else + hostname -I +fi +echo "" +sys.info "Public IP:" +public_ip=$(curl ifconfig.co/json) +ip=$(echo "$public_ip" | jq -r '.ip') +city=$(echo "$public_ip" | jq -r '.city') +region=$(echo "$public_ip" | jq -r '.region_name') +zip=$(echo "$public_ip" | jq -r '.zip_code') +country=$(echo "$public_ip" | jq -r '.country') +lat=$(echo "$public_ip" | jq -r '.latitude') +long=$(echo "$public_ip" | jq -r '.longitude') +time_zone=$(echo "$public_ip" | jq -r '.time_zone') +asn_org=$(echo "$public_ip" | jq -r '.asn_org') +echo "" +echo "IP: $ip" +echo "" +echo "${ORANGE}Address:${RESET} $city, $region, $zip, $country" +echo "${ORANGE}Latitude & Longitude:${RESET} ($lat, $long)" +echo "${ORANGE}Timezone:${RESET} $time_zone" +echo "${ORANGE}ASN Org:${RESET} $asn_org" + +echo "" +sys.info "Eth0 MAC Address:" +if sys.mac; then + ifconfig en1 | awk '/ether/{print $2}' +else + cat "/sys/class/net/$(ip route show default | awk '/default/ {print $5}')/address" +fi +echo "" \ No newline at end of file diff --git a/src/commands/issues.sh b/src/commands/issues.sh new file mode 100644 index 0000000..8400b6a --- /dev/null +++ b/src/commands/issues.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +sys.info "Redirecting to Issues on $repo_url..." +wgit.giturl "https://github.com/$repo_url/issues" \ No newline at end of file diff --git a/src/commands/keystore.sh b/src/commands/keystore.sh new file mode 100644 index 0000000..5d93120 --- /dev/null +++ b/src/commands/keystore.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +if wixd.arggt "1"; then + if wixd.arggt "2"; then + wixd.check_keystore "$1" "$2" + else + wixd.check_keystore "$1" + fi +else + read -rp "${GREEN}Enter the key you would like to add to your keystore:${RESET} " key + wixd.check_keystore "$key" +fi +sys.info "You're done!" \ No newline at end of file diff --git a/src/commands/lastcmd.sh b/src/commands/lastcmd.sh new file mode 100644 index 0000000..7b95376 --- /dev/null +++ b/src/commands/lastcmd.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +lastcmd=$(fc -ln -1) +trimmed=$(echo "$lastcmd" | xargs) +sys.clipboard "$trimmed" \ No newline at end of file diff --git a/src/commands/lastcommit.sh b/src/commands/lastcommit.sh new file mode 100644 index 0000000..f410e07 --- /dev/null +++ b/src/commands/lastcommit.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +sys.clipboard "$(git rev-parse HEAD)" +git show HEAD \ No newline at end of file diff --git a/src/commands/leap-year.sh b/src/commands/leap-year.sh new file mode 100644 index 0000000..21ba626 --- /dev/null +++ b/src/commands/leap-year.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +date=$(date) +year="${date:24:29}" + +if [[ "$year" =~ ^[0-9]*00$ ]]; then + if [ "$((year % 400))" -eq 0 ]; then + sys.info "$year is a leap year" + else + sys.info "$year is not a leap year" + fi +elif [ "$((year % 4))" -eq 0 ]; then + sys.info "$year is a leap year" +else + sys.info "$year is not a leap year" +fi +next_one=$((year + 4 - (year % 4))) +sys.info "The next leap year is $next_one" \ No newline at end of file diff --git a/src/commands/moon.sh b/src/commands/moon.sh new file mode 100644 index 0000000..628fa3a --- /dev/null +++ b/src/commands/moon.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +sys.info "Getting moon phase..." +curl wttr.in/moon \ No newline at end of file diff --git a/src/commands/mpull.sh b/src/commands/mpull.sh new file mode 100644 index 0000000..8e712e9 --- /dev/null +++ b/src/commands/mpull.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +if [ "$(git branch --list master)" ]; then + wgit.pull "master" +elif [ "$(git branch --list main)" ]; then + wgit.pull "main" +else + sys.warn "No master or main branch found..." +fi \ No newline at end of file diff --git a/src/commands/mydirs.sh b/src/commands/mydirs.sh new file mode 100644 index 0000000..cb3085a --- /dev/null +++ b/src/commands/mydirs.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +cat "$WIX_DATA_DIR/dir-aliases.txt" \ No newline at end of file diff --git a/src/commands/myorgs.sh b/src/commands/myorgs.sh new file mode 100644 index 0000000..1a811c9 --- /dev/null +++ b/src/commands/myorgs.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +cat "$WIX_DATA_DIR/git-orgs.txt" \ No newline at end of file diff --git a/src/commands/myscripts.sh b/src/commands/myscripts.sh new file mode 100644 index 0000000..4285dea --- /dev/null +++ b/src/commands/myscripts.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +cat "$WIX_DATA_DIR/run-configs.txt" \ No newline at end of file diff --git a/src/commands/nb.sh b/src/commands/nb.sh new file mode 100644 index 0000000..f582af5 --- /dev/null +++ b/src/commands/nb.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +if wixd.arggt "1" ; then + wgit.npush "$1" +else + sys.info "Provide a branch name:" + read -r name + if [ "$name" != "" ]; then + wgit.npush "$name" + else + sys.error "Invalid branch name" + fi +fi \ No newline at end of file diff --git a/src/commands/newscript.sh b/src/commands/newscript.sh new file mode 100644 index 0000000..d47eed5 --- /dev/null +++ b/src/commands/newscript.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +name="$1" +if ! wixd.arggt "1"; then + sys.info "What would you like to call your script? (no spaces)" + read -r name_prompt + name="$name_prompt" +fi +if [ -f "$WIX_DATA_DIR/$name.sh" ]; then + sys.error "Error: this script name already exists" +else + sys.info "Creating new script..." + echo "$name=$name" >> "$WIX_DATA_DIR/run-configs.txt" + touch "$WIX_DATA_DIR/run-configs/$name.sh" + chmod u+x "$WIX_DATA_DIR/run-configs/$name.sh" + sys.editfile "$WIX_DATA_DIR/run-configs/$name.sh" +fi \ No newline at end of file diff --git a/src/commands/notifs.sh b/src/commands/notifs.sh new file mode 100644 index 0000000..8b4d365 --- /dev/null +++ b/src/commands/notifs.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +sys.info "Redirecting to your Notifications..." +wgit.giturl "https://github.com/notifications" \ No newline at end of file diff --git a/src/commands/org.sh b/src/commands/org.sh new file mode 100644 index 0000000..05fa903 --- /dev/null +++ b/src/commands/org.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +if wixd.arggt "1"; then + if wixd.orgexists "$1"; then + wgit.giturl "https://github.com/$(wixd.org $1)" + else + sys.error "That organisation does not exist..." + sys.info "Execute 'wix myorgs' to see your saved organisations" + fi +else + wgit.giturl "https://github.com/$(wixd.org default)" +fi \ No newline at end of file diff --git a/src/commands/pr.sh b/src/commands/pr.sh new file mode 100644 index 0000000..f33d34d --- /dev/null +++ b/src/commands/pr.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +sys.info "Creating PR for $branch in $repo_url..." +wgit.giturl "https://github.com/$repo_url/pull/new/$branch" \ No newline at end of file diff --git a/src/commands/profile.sh b/src/commands/profile.sh new file mode 100644 index 0000000..f1deac1 --- /dev/null +++ b/src/commands/profile.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +sys.openurl "https://github.com/$(wixd.user.username)" \ No newline at end of file diff --git a/src/commands/prs.sh b/src/commands/prs.sh new file mode 100644 index 0000000..75bd55e --- /dev/null +++ b/src/commands/prs.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +sys.info "Redirecting to Pull Requests on $repo_url..." +wgit.giturl "https://github.com/$repo_url/pulls" \ No newline at end of file diff --git a/src/commands/pull.sh b/src/commands/pull.sh new file mode 100644 index 0000000..0b5420a --- /dev/null +++ b/src/commands/pull.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +if wixd.arggt "1" ; then + wgit.pull "$1" +else + wgit.pull "$branch" +fi \ No newline at end of file diff --git a/src/commands/push.sh b/src/commands/push.sh new file mode 100644 index 0000000..fe31913 --- /dev/null +++ b/src/commands/push.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +if wixd.arggt "1" ; then + wgit.push "$1" +else + wgit.push "$branch" +fi \ No newline at end of file diff --git a/src/commands/repo.sh b/src/commands/repo.sh new file mode 100644 index 0000000..02241a5 --- /dev/null +++ b/src/commands/repo.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +sys.info "Redirecting to $repo_url..." +wgit.giturl "https://github.com/$repo_url" \ No newline at end of file diff --git a/src/commands/run.sh b/src/commands/run.sh new file mode 100644 index 0000000..5c2e997 --- /dev/null +++ b/src/commands/run.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +wixd.run "$@" \ No newline at end of file diff --git a/scripts/photo_upscale.py b/src/commands/scripts/photo_upscale.py similarity index 100% rename from scripts/photo_upscale.py rename to src/commands/scripts/photo_upscale.py diff --git a/scripts/random_string_gen.py b/src/commands/scripts/random_string_gen.py similarity index 100% rename from scripts/random_string_gen.py rename to src/commands/scripts/random_string_gen.py diff --git a/scripts/services/logger.py b/src/commands/scripts/services/logger.py similarity index 100% rename from scripts/services/logger.py rename to src/commands/scripts/services/logger.py diff --git a/scripts/services/openai_service.py b/src/commands/scripts/services/openai_service.py similarity index 85% rename from scripts/services/openai_service.py rename to src/commands/scripts/services/openai_service.py index 91d2acb..cc21a1c 100644 --- a/scripts/services/openai_service.py +++ b/src/commands/scripts/services/openai_service.py @@ -10,14 +10,15 @@ def read_file(file_path): class OpenAIService: FILE_PATH = os.path.dirname(os.path.abspath(__file__)) - REPO_PATH = FILE_PATH.replace("/scripts/services", "") + REPO_PATH = FILE_PATH.replace("/src/commands/scripts/services", "") LOCAL_PATH = os.getcwd() LOCAL_README_PATH = f"{LOCAL_PATH}/.github/README.md" if os.path.exists(f"{LOCAL_PATH}/.github/README.md") else (f"{LOCAL_PATH}/README.md" if os.path.exists(f"{LOCAL_PATH}/README.md") else "") LOCAL_README = ("\n\nFor context this is the repository's README file: \n" + read_file(LOCAL_README_PATH)) if os.path.exists(LOCAL_README_PATH) else "" KEY_PATH = f"{REPO_PATH}/.wix-cli-data/.env" KEY_NAME="OPENAI_API_KEY" ENGINE="gpt-3.5-turbo" - ASSISTANT_MESSAGE = { "role": "system", "content": f"You are a developer pushing code to a git repository. You are writing a commit message for the changes you have made. You must use the following bash git outputs to write an informative and relevant commit message. Make sure to ignore cache files and mention specifically which functions, classes or variables were modified/created/deleted and why.{LOCAL_README}"} + ASSISTANT_MESSAGE_DEV = { "role": "system", "content": f"You are the WIX-CLI Smart Commit bot. You must write an informative yet succinct commit message for the changes you can see have been made from the specified 'git ...' command outputs. Ignore cache files and mention specifically which functions, classes or variables were modified/created/deleted and why.{LOCAL_README}"} + ASSISTANT_MESSAGE = { "role": "system", "content": f"Your name is the WIX-CLI bot, you were created by Harry Wixley for a bash CLI project. You are an assistant setup on a command line to help developers with any queries they may have developer related or otherwise."} SEPARATOR="-"*110 MAX_TOKENS=4097 @@ -52,14 +53,16 @@ def get_git_diff(self): return f"`git diff` output: {os.popen('git diff').read()}, and `git status` output: {os.popen('git status').read()}." def get_commit_title(self): + chat_history = [self.ASSISTANT_MESSAGE_DEV] title_prompt = f"You are in a team of developers working on a project. Write a 1 line commit message less than or equal to 50 characters technically describing the following bash git outputs. {self.get_git_diff()} Do not mention anything about the branch these changes were made on. Mention specifically which functions, classes or variables were modified/created/deleted and why." - title_response = self.get_response(title_prompt) + title_response = self.get_response(title_prompt, chat_history) return f"GPT-commit: {title_response}" def get_commit_description(self): + chat_history = [self.ASSISTANT_MESSAGE_DEV] title = self.get_commit_title() description_prompt = f"You are in a team of developers working on a project. Write a 2 line commit message technically describing the following bash git outputs. {self.get_git_diff()} Do not repeat the title \"{title}\", and do not mention anything about the branch these changes were made on. Mention specifically which functions, classes or variables were modified/created/deleted and why." - description_response = self.get_response(description_prompt) + description_response = self.get_response(description_prompt, chat_history) return (title, description_response) def get_smart_commit(self): diff --git a/scripts/wifi_sniffer.py b/src/commands/scripts/wifi_sniffer.py similarity index 100% rename from scripts/wifi_sniffer.py rename to src/commands/scripts/wifi_sniffer.py diff --git a/src/commands/setup.sh b/src/commands/setup.sh new file mode 100644 index 0000000..5b8c381 --- /dev/null +++ b/src/commands/setup.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +if [ "$1" = "openai_key" ]; then + sys.info "Setting up OpenAI key..." + echo "" + wixd.check_keystore "OPENAI_API_KEY" + sys.info "You're done!" + +elif [ "$1" = "smart_commit" ]; then + sys.info "Setting up smart commit..." + echo "" + wixd.check_keystore "OPENAI_API_KEY" + wixd.check_keystore "USE_SMART_COMMIT" "true" + sys.info "You're done!" + +else + sys.error "Invalid setup command! Try again" + echo "Type 'wix' to see the list of available commands (and their arguments), or 'wix help' to be redirected to more in-depth online documentation" +fi \ No newline at end of file diff --git a/src/commands/speedtest.sh b/src/commands/speedtest.sh new file mode 100644 index 0000000..df58290 --- /dev/null +++ b/src/commands/speedtest.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +sys.info "Running speedtest..." +speedtest \ No newline at end of file diff --git a/src/commands/sys-info.sh b/src/commands/sys-info.sh new file mode 100644 index 0000000..45ebf50 --- /dev/null +++ b/src/commands/sys-info.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +if sys.using_zsh; then + echo "ZSH (0_0)" +else + echo "BASH (-_-)" +fi \ No newline at end of file diff --git a/src/commands/todo.sh b/src/commands/todo.sh new file mode 100644 index 0000000..bf9727e --- /dev/null +++ b/src/commands/todo.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +cat "$WIX_DATA_DIR/todo.txt" \ No newline at end of file diff --git a/src/commands/upscale.sh b/src/commands/upscale.sh new file mode 100644 index 0000000..5b5a19e --- /dev/null +++ b/src/commands/upscale.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +fname="$1" +alpha="$2" +if ! wixd.arggt "1"; then + sys.info "Enter the file you would like to upscale:" + read -r url + fname="$url" + + if ! wixd.arggt "2"; then + sys.info "Enter the scale multiplier:" + read -r mult + alpha="$mult" + fi +fi +sys.info "Upscaling $fname..." +python3 "$WIX_SCRIPT_DIR/photo_upscale.py" "$fname" "$alpha" \ No newline at end of file diff --git a/src/commands/user.sh b/src/commands/user.sh new file mode 100644 index 0000000..894ad0e --- /dev/null +++ b/src/commands/user.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +cat "$WIX_DATA_DIR/git-user.txt" \ No newline at end of file diff --git a/src/commands/version.sh b/src/commands/version.sh new file mode 100644 index 0000000..83b4d40 --- /dev/null +++ b/src/commands/version.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "v$version" \ No newline at end of file diff --git a/src/commands/vsc.sh b/src/commands/vsc.sh new file mode 100644 index 0000000..92edb2c --- /dev/null +++ b/src/commands/vsc.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +if wixd.direxists "$1"; then + wixd.cd "$1" + sys.info "Opening up VSCode editor..." + code . +else + sys.error "Error: this directory alias does not exist, please try again" +fi \ No newline at end of file diff --git a/src/commands/weather.sh b/src/commands/weather.sh new file mode 100644 index 0000000..f05e69b --- /dev/null +++ b/src/commands/weather.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +if wixd.arggt "1"; then + city="$1" + sys.info "Getting weather for $city..." + curl wttr.in/"$city" +else + sys.info "Getting weather for your current location..." + curl wttr.in +fi \ No newline at end of file diff --git a/src/commands/webtext.sh b/src/commands/webtext.sh new file mode 100644 index 0000000..f3b8f3c --- /dev/null +++ b/src/commands/webtext.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +if wixd.arggt "1"; then + sys.webtext "$1" +else + sys.info "Enter the webpage you would like to parse:" + read -r webpage + sys.webtext "$webpage" +fi diff --git a/src/commands/wifi.sh b/src/commands/wifi.sh new file mode 100644 index 0000000..6cc6e87 --- /dev/null +++ b/src/commands/wifi.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +if sys.mac; then + /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport scan +else + python3 "${WIX_SCRIPT_DIR}/wifi_sniffer.py" +fi \ No newline at end of file diff --git a/src/commands/wpass.sh b/src/commands/wpass.sh new file mode 100644 index 0000000..03b3fdc --- /dev/null +++ b/src/commands/wpass.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +if sys.mac; then + sys.info "Enter the SSID of the network you would like to get the password for:" + read -r ssid + sys.info "Getting password for $ssid..." + security find-generic-password -ga "$ssid" | grep "password:" + echo "" +else + sys.info "Listing saved Wifi passwords:" + sudo grep -r '^psk=' /etc/NetworkManager/system-connections/ +fi \ No newline at end of file diff --git a/src/data/arg_scripts.csv b/src/data/arg_scripts.csv new file mode 100644 index 0000000..4f38402 --- /dev/null +++ b/src/data/arg_scripts.csv @@ -0,0 +1,62 @@ +id,path,name,public,args +sys-info,sys-info,"Get Shell Type",true, +cd,cd,"Navigate Directory Aliases",true, +back,back,"Go Back A Directory",true, +run,run,"Run Script Aliases",true,"" +vsc,vsc,"Open Directory Aliases in VSCode",true,"" +genpass,genpass,"Generate A Random Password",true,"" +genhex,genhex,"Generate A Random Hex String",true +genb64,genb64,"Generate A Random Base64 String",true +version,version,"WIX-CLI Version",true +-v,version,"WIX-CLI Version",false +--v,version,"WIX-CLI Version",false +ginit,ginit,"Initialise Git Repository",true +push,push,"Add, Commit, & Push Git Changes",true +pull,pull,"Pull Git Changes",true +mpull,mpull,"Pull Git Changes From Master/Main Branch",true +repo,repo,"View Your Repository On GitHub",true +branch,branch,"View Your Current Branch On GitHub",true +actions,actions,"View Your Repository Actions On GitHub",true +issues,issues,"View Your Repository Issues On GitHub",true +prs,prs,"View Your Repository PRs On GitHub",true +notifs,notifs,"View Your GitHub Notifications",true +commits,commits,"View Your Branch Git Commits",true +lastcommit,lastcommit,"View Your Last Commit & Copy It's ID",true +nb,nb,"Checkout, Add, Commit, & Push A New Git Branch",true +pr,pr,"Open A Pull Request From Your Current Git Branch on GitHub",true +bpr,bpr,"Checkout, Add, Commit, & Push A New Git Branch, Then Open A PR For It On GitHub",true +profile,profile,"View Your GitHub Profile",true +org,org,"View Your GitHub Organisation",true +help,help,"View WIX-CLI Documentation",true +user,user,"View Your User Configuration",true +mydirs,mydirs,"View Your Directory Aliases Configuration",true +myorgs,myorgs,"View Your GitHub Organisation Configuration",true +myscripts,myscripts,"View Your Scripts Configuration",true +todo,todo,"View Your To-Do List",true +editd,editd,"Edit Your WIX-CLI Configuration",true +edits,edits,"Edit A Script File",true +newscript,newscript,"Create A New Script",true +find,find,"Regex Search Current Directory For File",true +lastcmd,lastcmd,"Copy Your Last Command To Your Clipboard",true +ip,ip,"View Your Local & Public IPs",true +wifi,wifi,"View Available WiFi Networks",true +hardware-ports,hardware-ports,"View Your Hardware Ports",true +wpass,wpass,"View Your Saved WiFi Passwords",true +speedtest,speedtest,"Run A Speed Test On Your Network",true +genqr,genqr,"Generate a QR code from a URL",true +upscale,upscale,"Scale up an image, uses no smoothing",true +fopen,fopen,"Open current directory in your files application",true +encrypt,encrypt,"Encrypt a file using GPG",true +decrypt,decrypt,"Decrypt a GPG-encrypted file",true +weather,weather,"View the weather forecast for your location in the terminal2,true +moon,moon,"View the moon phase",true +leap-year,leap-year,"Check when the next leap year is",true +webtext,webtext,"Read-only websites in your terminal",true +explain,explain,"Explain a bash command",true +ask-gpt,ask-gpt,"Start a conversation with ChatGPT",true +google,google,"Google a query",true +install-deps,install-deps,"Install WIX-CLI dependencies",true +keystore,keystore,"Add a key-value pair to your '.env' keystore",true +setup,setup,"Setup WIX-CLI Third Party API-based utilities",true +img_stdout,img_stdout,"Output wix STDOUT to an image",false +copy,copy,"Copy output of a command to clipboard",true, \ No newline at end of file diff --git a/wix-cli.sh b/wix-cli.sh index 27c3c21..130f238 100755 --- a/wix-cli.sh +++ b/wix-cli.sh @@ -2,9 +2,13 @@ # CLI CONSTS mypath=$(readlink -f "${BASH_SOURCE:-$0}") -mydir=$(dirname "$mypath") +WIX_DIR=$(dirname "$mypath") +WIX_DATA_DIR=$WIX_DIR/.wix-cli-data +WIX_SCRIPT_DIR=$WIX_DIR/src/commands/scripts +export WIX_DIR WIX_DATA_DIR WIX_SCRIPT_DIR -source $mydir/functions.sh +source $(dirname ${BASH_SOURCE[0]})/src/classes/sys/sys.h +sys sys branch="" if git rev-parse --git-dir > /dev/null 2>&1; then @@ -25,16 +29,16 @@ pull() { } wix_update() { - info_text "Checking for updates..." + sys.info "Checking for updates..." current_dir=$(pwd) - cd "$mydir" || return 1 + cd "$WIX_DIR" || return 1 repo_branch="" if git rev-parse --git-dir > /dev/null 2>&1; then repo_branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p') fi if [ "$repo_branch" != "master" ]; then - warn_text "Not on master branch, skipping update" && echo "" + sys.warn "Not on master branch, skipping update" && echo "" cd "$current_dir" || return 1 return 1 fi @@ -46,9 +50,9 @@ wix_update() { BASE=$(git merge-base @ "$UPSTREAM") if [ "$LOCAL" = "$REMOTE" ]; then - info_text "Up-to-date" + sys.info "Up-to-date" elif [ "$LOCAL" = "$BASE" ]; then - info_text "Updating..." + sys.info "Updating..." pull "$branch" elif [ "$REMOTE" = "$BASE" ]; then echo "Need to push" @@ -65,5 +69,5 @@ wix_update "" # ARGPARSE -source "$mydir/completion.sh" -source "$mydir/argparse.sh" "${@:1}" \ No newline at end of file +source "$WIX_DIR/completion.sh" +source "$WIX_DIR/argparse.sh" "${@:1}" \ No newline at end of file