Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

GPT-commit: Refactor command names and modify scripts, classes, and s… #43

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source $(dirname ${BASH_SOURCE[0]})/src/classes/sys/sys.h

setup_alias() {
envfile=$(sys.envfile)
envfile=$(sys.shell.envfile)
{ echo ""; echo "# WIX CLI"; echo "alias wix=\"source $(pwd)/wix-cli.sh\""; } >> "$envfile"
source "$envfile"
}
Expand All @@ -14,14 +14,14 @@ setup_completion() {
}

# INITIAL SETUP
if ! sys.using_zsh; then
if ! sys.shell.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 sys.mac; then
if sys.os.mac; then
sys.info "Installing dependencies..."
brew install xclip jq
brew tap teamookla/speedtest
Expand Down
83 changes: 39 additions & 44 deletions src/classes/sys/sys.class
Original file line number Diff line number Diff line change
Expand Up @@ -37,96 +37,69 @@ sys.error() {
fi
}

# VALIDATION
sys.empty() {
if [ "$1" = "" ]; then
return 0
else
return 1
fi
}

# MAC & LINUX FUNCTIONS
sys.using_zsh() {
# Shell utilities
sys.shell.zsh() {
if [[ "$(ps -o args= -p $$)" = *"zsh"* ]]; then
return 0
else
return 1
fi
}

sys.openurl() {
if sys.using_zsh; then
open "$1"
else
{
xdg-open "$1"
} &> /dev/null
fi
}

sys.envfile() {
if sys.using_zsh; then
sys.shell.envfile() {
if sys.shell.zsh; then
echo "$HOME/.zshrc"
else
echo "$HOME/.bashrc"
fi
return 0
}

sys.arm() {
if sys.using_zsh; then
if [[ "$(sysctl -n sysctl.proc_translated)" == "1" ]] || [[ "$(uname -m)" == "arm64" ]]; then
return 0;
else
return 1;
fi
else
return 1;
fi
}
# System specifications

sys.openfile() {
xdg-open "file:///$1"
sys.cpu.architecture() {
uname -m
}

sys.mac() {
sys.os.mac() {
if [[ "$OSTYPE" == "darwin"* ]]; then
return 0
else
return 1
fi
}

sys.linux() {
sys.os.linux() {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
return 0
else
return 1
fi
}

sys.windows() {
sys.os.windows() {
if [[ "$OSTYPE" == "msys" ]]; then
return 0
else
return 1
fi
}

sys.wsl() {
sys.os.wsl() {
if [[ "$(uname -r)" == *"Microsoft"* ]]; then
return 0
else
return 1
fi
}

sys.webtext() {
# System utilities

sys.util.webtext() {
lynx -dump -cookies "$1"
}

sys.clipboard() {
sys.util.clipboard() {
if command -v pbcopy >/dev/null 2>&1; then
sys.info "This has been saved to your clipboard!"
echo "$1" | pbcopy
Expand All @@ -138,10 +111,32 @@ sys.clipboard() {
fi
}

sys.editfile() {
if sys.using_zsh; then
sys.util.editfile() {
if sys.shell.zsh; then
vi "$1"
else
gedit "$1"
fi
}

sys.util.openfile() {
xdg-open "file:///$1"
}

sys.util.openurl() {
if sys.shell.zsh; then
open "$1"
else
{
xdg-open "$1"
} &> /dev/null
fi
}

sys.util.empty() {
if [ "$1" = "" ]; then
return 0
else
return 1
fi
}
20 changes: 10 additions & 10 deletions src/classes/wgit/wgit.class
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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
if ! sys.util.empty "$branch" ; then
return 0
else
sys.error "This is not a git repository..."
Expand All @@ -17,13 +17,13 @@ wgit.is_git_repo(){

wgit.giturl(){
if wgit.is_git_repo ; then
sys.openurl "$1"
sys.util.openurl "$1"
fi
}

wgit.ginit(){
git init
if sys.empty "$2" ; then
if sys.util.empty "$2" ; then
sys.info "Provide a name for this repository:"
read -r rname
echo "# $rname" >> README.md
Expand All @@ -36,22 +36,22 @@ wgit.ginit(){
fi
wgit.commit "wix-cli: first commit"
git remote add origin "[email protected]:$1/$rname.git"
sys.openurl "https://github.com/$3"
sys.util.openurl "https://github.com/$3"
else
echo "# $2" >> README.md
wgit.commit "wix-cli: first commit"
git remote add origin "[email protected]:$1/$2.git"
sys.openurl "https://github.com/$3"
sys.util.openurl "https://github.com/$3"
fi
}

wgit.wix_ginit(){
if ! sys.empty "$1"; then
if ! sys.util.empty "$1"; then
mkdir "$1"
cd "$1" || return 1
fi

if sys.empty "$branch" ; then
if sys.util.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" ]
Expand All @@ -77,12 +77,12 @@ wgit.wix_ginit(){

wgit.commit() {
git add .
if sys.empty "$1" ; then
if sys.util.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
if sys.shell.zsh; then
sys.h2 "Title:${RESET} ${lines[1]}"
sys.h2 "Description:${RESET} ${lines[2]}"
echo ""
Expand Down Expand Up @@ -136,5 +136,5 @@ wgit.pull() {
wgit.bpr() {
wgit.npush "$1"
sys.info "Creating PR for $branch in $repo_url..."
sys.openurl "https://github.com/$repo_url/pull/new/$1"
sys.util.openurl "https://github.com/$repo_url/pull/new/$1"
}
2 changes: 1 addition & 1 deletion src/classes/wixd/wixd.class
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ wixd.cd() {
if [[ -v mydirs["$1"] ]]; then
alias_dest="${mydirs[$1]}"
destination="${alias_dest/~/${HOME}}"
if ! sys.empty "$2" ; then
if ! sys.util.empty "$2" ; then
destination="${alias_dest/~/${HOME}}/$2"
fi
sys.info "Travelling to -> $destination"
Expand Down
8 changes: 4 additions & 4 deletions src/commands/copy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
if wixd.arggt "1"; then
if [[ "$1" =~ ^\$\(.*\)$ ]]; then
DATA="$1"
sys.clipboard "$DATA"
sys.util.clipboard "$DATA"
else
sys.clipboard "$1"
sys.util.clipboard "$1"
fi
else
sys.info "Enter the text you would like to copy to your sys.clipboard:"
sys.info "Enter the text you would like to copy to your sys.util.clipboard:"
read -r text
sys.clipboard "$text"
sys.util.clipboard "$text"
fi
10 changes: 5 additions & 5 deletions src/commands/editd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ if ! wixd.arggt "1"; then
fi
fi
if [ "$data_to_edit" = "user" ]; then
sys.editfile "$WIX_DATA_DIR/git-user.txt"
sys.util.editfile "$WIX_DATA_DIR/git-user.txt"
elif [ "$data_to_edit" = "myorgs" ]; then
sys.editfile "$WIX_DATA_DIR/git-orgs.txt"
sys.util.editfile "$WIX_DATA_DIR/git-orgs.txt"
elif [ "$data_to_edit" = "mydirs" ]; then
sys.editfile "$WIX_DATA_DIR/dir-aliases.txt"
sys.util.editfile "$WIX_DATA_DIR/dir-aliases.txt"
elif [ "$data_to_edit" = "myscripts" ]; then
sys.editfile "$WIX_DATA_DIR/run-configs.txt"
sys.util.editfile "$WIX_DATA_DIR/run-configs.txt"
elif [ "$data_to_edit" = "todo" ]; then
sys.editfile "$WIX_DATA_DIR/todo.txt"
sys.util.editfile "$WIX_DATA_DIR/todo.txt"
fi
2 changes: 1 addition & 1 deletion src/commands/edits.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if ! wixd.arggt "1"; then
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"
sys.util.editfile "$WIX_DATA_DIR/run-configs/$script_to_edit.sh"
else
sys.error "This script does not exist... Please try again"
fi
4 changes: 2 additions & 2 deletions src/commands/explain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ if wixd.arggt "1"; then
cmd="$1"
sys.info "Finding explanation for $cmd..."
cmd="${cmd// /+}"
sys.openurl "https://explainshell.com/explain?cmd=$cmd"
sys.util.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"
sys.util.openurl "https://explainshell.com/explain?cmd=$cmd"
fi
4 changes: 2 additions & 2 deletions src/commands/fopen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ if wixd.arggt "1"; then
if wixd.direxists "$dir"; then
mydir="${mydirs[$dir]/\~/${HOME}}"
sys.info "Opening $WIX_DIR..."
sys.openfile "$WIX_DIR"
sys.util.openfile "$WIX_DIR"
else
sys.error "Directory alias does not exist"
fi
else
sys.info "Opening current directory..."
sys.openfile "$(pwd)"
sys.util.openfile "$(pwd)"
fi
2 changes: 1 addition & 1 deletion src/commands/genb64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ 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"
sys.util.clipboard "$truncated_pass"
2 changes: 1 addition & 1 deletion src/commands/genhex.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ 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"
sys.util.clipboard "$truncated_pass"
2 changes: 1 addition & 1 deletion src/commands/genpass.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ if wixd.arggt "1"; then
fi
pass=$(python3 "${WIX_SCRIPT_DIR}/random_string_gen.py" "$pass_size")
sys.info "Your random password string is: ${RESET}$pass"
sys.clipboard "$pass"
sys.util.clipboard "$pass"
4 changes: 2 additions & 2 deletions src/commands/google.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash

if wixd.arggt "1"; then
sys.openurl "https://www.google.com/search?q=$1"
sys.util.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"
sys.util.openurl "https://www.google.com/search?q=$query"
fi
echo ""
2 changes: 1 addition & 1 deletion src/commands/hardware-ports.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if sys.mac; then
if sys.os.mac; then
networksetup -listallhardwareports
else
echo "Not supported on this OS"
Expand Down
2 changes: 1 addition & 1 deletion src/commands/help.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

sys.openurl "https://hwixley.github.io/WIX-CLI/index.html"
sys.util.openurl "https://hwixley.github.io/WIX-CLI/index.html"
Loading