Full Code of guarinogabriel/Mac-CLI for AI

master 26c047242351 cached
20 files
58.4 KB
15.1k tokens
1 requests
Download .txt
Repository: guarinogabriel/Mac-CLI
Branch: master
Commit: 26c047242351
Files: 20
Total size: 58.4 KB

Directory structure:
gitextract_i2r9ry5d/

├── .github/
│   └── stale.yml
├── .gitignore
├── LICENSE.md
├── README.md
├── mac
└── mac-cli/
    ├── completion/
    │   ├── bash_completion
    │   └── fish_completion
    ├── misc/
    │   └── help
    ├── plugins/
    │   ├── brew
    │   ├── dns
    │   ├── general
    │   ├── git
    │   ├── network
    │   ├── performance
    │   ├── search
    │   ├── ssh
    │   └── volume
    └── tools/
        ├── install
        ├── uninstall
        └── update

================================================
FILE CONTENTS
================================================

================================================
FILE: .github/stale.yml
================================================
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 60
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
  - pinned
  - security
# Label to use when marking an issue as stale
staleLabel: wontfix
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
  This issue has been automatically marked as stale because it has not had
  recent activity. It will be closed if no further activity occurs. Thank you
  for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false


================================================
FILE: .gitignore
================================================
.DS_Store
.idea/
.idea/workspace.xml
.phpstorm.meta.php
*.iml

================================================
FILE: LICENSE.md
================================================
Copyright (c) 2015-2022 Gabriel Guarino

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

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

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


================================================
FILE: README.md
================================================
# Mac CLI

 macOS command line tools for developers


---

### Sponsors

>[![Sponsor logo](images/sponsor-icon.png)](https://apps.apple.com/us/app/superplanner/id6443725564)
>
>Mac CLI is sponsored by 📒 [SuperPlanner](https://superplanner.app/), an innovative daily planner and task manager for iPhone, iPad and Mac.
>
>SuperPlanner combines the calendar with task management features to keep everything organized in one place.
>
>There is no login or user registration required. All data is stored locally and syncs between your devices using private and secure iCloud sync.
>
>[![Sponsor download badge](images/sponsor-download-badge.png)](https://apps.apple.com/us/app/superplanner/id6443725564)

---

### Introduction

Mac CLI is the ultimate tool for developers to manage their Mac. It provides a huge set of command line commands that automate the usage of your macOS system.
When you run a function, the executed command is displayed and that helps you memorize each of the Utilities for future usage.

The tool is designed to be easily extendable with additional commands through the use of plugins. To view the currently available commands, you can navigate to the plugins folder and explore the different categories: [/mac-cli/plugins](https://github.com/guarinogabriel/mac-cli/tree/master/mac-cli/plugins)

_Contributions to add new plugins and keep improving the existing ones are welcome and very much appreciated!_

![image](images/demo.gif)

---

### Installation in 1 Simple Step - Including Configuration Wizard!

Via curl
> `sh -c "$(curl -fsSL https://raw.githubusercontent.com/guarinogabriel/mac-cli/master/mac-cli/tools/install)"`

Via wget
> `sh -c "$(wget https://raw.githubusercontent.com/guarinogabriel/mac-cli/master/mac-cli/tools/install -O -)"`

Then, re-open your terminal client. You will be able to run all the commands listed below, for example:
> `mac help`

---

### Configuration

The configuration is done when you install Mac CLI for the first time though the installer configuration wizard.
After that, you can update your Mac CLI configuration by editing the following file: `/usr/local/bin/mac`

---

### Requirements

These are the requirements to be able to run all the commands (the dependencies/requirements are installed when you install Mac CLI for the first time):

* Homebrew
* Git
* Pipe Viewer (pv)

---

### Update

You can update Mac CLI to the latest version by running:
> `sh -c "$(curl -fsSL https://raw.githubusercontent.com/guarinogabriel/mac-cli/master/mac-cli/tools/update)"`

---

### Uninstallation

You can uninstall Mac CLI by running:
> `sh -c "$(curl -fsSL https://raw.githubusercontent.com/guarinogabriel/mac-cli/master/mac-cli/tools/uninstall)"`

---

### Help / Commands List

| Command  | Description | Arguments |
| ------------- | ------------- | ------------- |
| `mac help`  | List all available commands in mac script  | |

### General Commands

| Command  | Description | Arguments |
| ------------- | ------------- | ------------- |
| `mac update`  | Install macOS software updates, update installed Ruby gems, Homebrew, npm and their installed packages | |
| `mac lock`  | Lock  | |
| `mac restart`  | Restart macOS  | |
| `mac sleep`  | Sleep mode  | |
| `mac shutdown`  | Shutdown  | |
| `mac time`  | Show clock at top right position in Terminal/iTerm | |
| `mac screensaver`  | Start screensaver  | |
| `mac folders:list`  | List folders in current directory with their current size | |
| `mac folder:size`  | Calculate current folder size  | |
| `mac bluetooth:status`  | Get the bluetooth status  | |
| `mac bluetooth:enable`  | Enable bluetooth  | |
| `mac bluetooth:disable`  | Disable bluetooth  | |
| `mac wifi:status`  | Get the wifi status  | |
| `mac wifi:scan`  | Scan available wifi networks  | |
| `mac wifi:enable`  | Enable wifi  | |
| `mac wifi:disable`  | Disable wifi  | |
| `mac dock:add-space N`  | Add blank space to dock  | N = number of spaces |
| `mac eject-all`  | Eject all mounted volumes and disks  | |
| `mac battery`  | Get battery status  | |
| `mac info`  | Get macOS version information  | |
| `mac hidden:show`  | Show hidden files  | |
| `mac hidden:hide`  | Hide hidden files  | |
| `mac find:text X`  | Find exact phrase recursively inside directory | X = Text string |
| `mac find:biggest-files`  | Find biggest files inside directory  | |
| `mac find:biggest-directories`  | Find biggest directories inside directory | |
| `mac zip:extract X` | Extract Zip file to current folder | X = Zip file to extract |
| `mac gzip:compress X` | Compress current file using Gzip | X = File to compress |
| `mac gzip:extract X` | Extract Gzip file to current folder | X = Gzip file to extract |
| `mac tar:compress X`  | Compress X file/directory using tar with progress indicator | X = File or directory |
| `mac tar:extract X` | Extract tar file to current folder | X = Tar file to extract |


### Search Utilities

| Command  | Description | Arguments |
| ------------- | ------------- | ------------- |
| `mac find:recent N`  | Find files modified in the last N minutes  |  N = number of minutes  |
| `mac search:replace X` | Search and replace string in file | X = File to perform the search and replace operation |


### Network Utilities

| Command  | Description |
| ------------- | ------------- |
| `mac speedtest`  | Internet connection speed test  |
| `mac ports`  | List of used ports  |
| `mac ip:local`  | Get local IP address  |
| `mac ip:public`  | Get public IP address  |


### DNS Utilities

| Command  | Description |
| ------------- | ------------- |
| `mac dns:list`  | List DNS server(s)  |
| `mac dns:add`  | Add DNS server  |
| `mac dns:remove`  | Remove DNS server  |
| `mac dns:flush`  | Flush DNS cache  |


### SSH Utilities

| Command  | Description | Arguments |
| ------------- | ------------- | ------------- |
| `mac ssh:download-file X`  | Download file from remote server through SSH  |  X = Path of the remote file to download  |
| `mac ssh:download-folder X`  | Download entire folder from remote server through SSH  |  X = Path of the remote folder to download  |
| `mac ssh:sync:local X`  | Sync local folder with remote folder using rsync through SSH (download remote folder to local folder)  |  X = Path of the remote folder to sync to local folder  |
| `mac ssh:sync:remote X`  | Sync remote folder with local folder using rsync through SSH (upload local folder to remote folder)  |  X = Path of the remote folder to sync from local folder  |
| `mac ssh:upload X`  | Upload file to remote server through SSH  |  X = Path of the file to upload to the remote server  |
| `mac ssh:public-key`  | Copy SSH Public Key  |  |
| `mac ssh:list`  | List all the saved SSH credentials  |  |


### Performance and maintenance Utilities

| Command  | Description |
| ------------- | ------------- |
| `mac system`  | Show system information to review mac performance  |
| `mac temp`  | Show temperature, fan and battery statistics  |
| `mac memory`  | See memory usage sorted by memory consumption  |
| `mac trash:empty`  | Empty trash |
| `mac trash:size`  | Calculate trash size |


### Git Utilities

| Command  | Description |
| ------------- | ------------- |
| `mac git:config`  | Display local Git configuration  |
| `mac git:open`  | Open current repository on Github  |
| `mac git:create:branch`  | Create branch based on current branch  |
| `mac git:branches:date`  | Get last update date for all branches in current project  |
| `mac git:undo-commit`  | Undo latest commit  |
| `mac git:log`  | See latest commits IDs and titles for current branch  |
| `mac git:branch`  | See all branches  |
| `mac git:branch:rename`  | Rename Git branch |
| `mac git:branch:remove-local`  | Remove local Git branch |
| `mac git:branch:remove-remote`  | Remove local and remote Git branch |
| `mac git:settings`  | Check Git settings  |
| `mac git:add-removed`  | Add removed files to staged files  |
| `mac git:size`  | Get size for current Git directory  |

### Homebrew Utilities

| Command  | Description |
| ------------- | ------------- |
| `mac brew`  | Get a list of installed Homebrew packages  |


================================================
FILE: mac
================================================
#!/bin/sh
###########################################################################
#  mac CLI (mac command line tools) - macOS command line tools for developers
###########################################################################

# Version: 2.0
# Date: December 8, 2015
# Author: Gabriel Guarino
#
# Collection of useful functions to automate macOS common tasks
#
###########################################################################

# Mac CLI directory
MAC="$(dirname "$0")"

#--------------------------------------------------------------------
# Configuration
#--------------------------------------------------------------------
export echocommand="true"

#--------------------------------------------------------------------
# Parameters
#--------------------------------------------------------------------
export fn=$1
export firstParameter=$2
export secondParameter=$3
export allParameters=${@:2}

#--------------------------------------------------------------------
# Colors
#--------------------------------------------------------------------
export GREEN='\033[0;32m'
export GRAY='\033[0;37m'
export LIGHTBLUE='\033[1;34m'
export LIGHTGREEN='\033[1;32m'
export WHITEBOLD='\033[1;37m'
export RED='\033[1;31m'
export NC='\033[0m' # No Color

#--------------------------------------------------------------------
# List of Commands
#--------------------------------------------------------------------

COMMANDS=(
    list
    help
    usage
    categories
    general
    search
    network
    dns
    ssh
    webdev
    performance
    terminal
    git
    web_utilities
    homebrew
    image
    magento
    update
    upgrade
    uninstall
    lock
    restart
    sleep
    display
    shutdown
    uptime
    volume
    volume:ismute
    volume:mute
    volume:unmute
    hidden:show
    hidden:hide
    screensaver
    folders:list
    folder:size
    dock:add-space
    bluetooth:status
    bluetooth:enable
    bluetooth:disable
    wifi:status
    wifi:scan
    wifi:enable
    wifi:disable
    eject-all
    battery
    info
    find:text
    find:biggest-files
    find:biggest-directories
    zip:extract
    gzip:compress
    gzip:extract
    tar:compress
    tar:extract
    find:recent
    search:replace
    speedtest
    ports
    ip:local
    ip:public
    dns:list
    dns:add
    dns:remove
    dns:flush
    hosts:edit
    ssh:download-file
    ssh:download-folder
    ssh:sync:local
    ssh:sync:remote
    ssh:upload
    ssh:public-key
    ssh:list
    system
    temp
    memory
    trash:empty
    trash:size
    git:config
    git:open
    git:create:branch
    git:branches:date
    git:undo-commit
    git:log
    git:branch
    git:branch:rename
    git:branch:remove-local
    git:branch:remove-remote
    git:branch
    git:settings
    git:add-removed
    git:size
    brew:update
)
## ---- END OF COMMANDS; Comment required for bash_completion------

if [ -z "$fn" ] || [[ "$#" -lt "1" ]]; then
    fn="list"
fi

#--------------------------------------------------------------------
# Help
#--------------------------------------------------------------------

# Documentation / Help
source "$MAC/mac-cli/misc/help"

#--------------------------------------------------------------------
# Catch command not found
#--------------------------------------------------------------------

if [[ ! " ${COMMANDS[@]} " =~ " ${fn} " ]]; then
    echo "${RED}Command not found: '${fn}' $(test ! -z "$allParameters" -a "$allParameters" != " " && echo "\nParameters: $allParameters" || echo "")${NC}"
    read -p "Choose a category for which to list help/usage... ($(categoriesList)) " category # Ask user for a category to print usage

    if [ ! -z "${category}" ]; then
        echo "$(usageList ${category})\n" # Show help/usage for user-selected category
        echo "$(printAdditionalHelp)"
    else
        kill -INT $$ # Exit
    fi
fi

#--------------------------------------------------------------------
# Plugins
#--------------------------------------------------------------------

source "$MAC/mac-cli/plugins/brew"
source "$MAC/mac-cli/plugins/general"
source "$MAC/mac-cli/plugins/git"
source "$MAC/mac-cli/plugins/network"
source "$MAC/mac-cli/plugins/dns"
source "$MAC/mac-cli/plugins/performance"
source "$MAC/mac-cli/plugins/search"
source "$MAC/mac-cli/plugins/ssh"
source "$MAC/mac-cli/plugins/volume"


================================================
FILE: mac-cli/completion/bash_completion
================================================
# Mac_CLI bash completion

have mac && {
_mac() {
    local MACWORDS cur

    COMPREPLY=()
    _get_comp_words_by_ref -n : cur

    MACWORDS=$(awk "/COMMANDS=/,/#/" < /usr/local/bin/mac  | tail -n +2 | sed '/)/d;/#/d')

    COMPREPLY=( $( compgen -W "$MACWORDS" -- "$cur" ) )

    __ltrim_colon_completions "$cur"
}
complete -F _mac mac
}

================================================
FILE: mac-cli/completion/fish_completion
================================================
complete -c mac -a (awk "/COMMANDS=/,/#/" < /usr/local/bin/mac  | tail -n +2 | sed '/)/d;/#/d' | tr -d '\n')


================================================
FILE: mac-cli/misc/help
================================================
#!/bin/sh

#--------------------------------------------------------------------
# mac script commands list - all commands
#--------------------------------------------------------------------

MacCategories=(
general
git
homebrew
lamp
network
dns
performance
search
ssh
terminal
web_utilities
webdev
)

function printInfo()
{
    echo "\n${WHITEBOLD} mac CLI – OS X command line tools for developers"
    echo "====================================================${NC}"
}

function printAdditionalHelp()
{
    echo "\nRun ${LIGHTBLUE}mac help${NC} for full usage, ${LIGHTBLUE}mac categories${NC} for categories list, or ${LIGHTBLUE}mac {category}${NC} for usage related to {category}"
    echo "${NC}\n"
}

function categoriesList()
{
    cats=${cats}$(printf "%s|" "${MacCategories[@]}")
    cats="${cats%?}"
    echo "${cats}"
}

function usageList()
{
    case ${1} in
        general)
            echo "\n${WHITEBOLD}General Utilities: "
            echo "${LIGHTBLUE}mac update${GRAY}: Install OS X software updates, update installed Ruby gems, Homebrew, npm and their installed packages"
            echo "${LIGHTBLUE}mac upgrade${GRAY}: Upgrade Mac CLI to the latest version"
            echo "${LIGHTBLUE}mac uninstall${GRAY}: Uninstall Mac CLI"
            echo "${LIGHTBLUE}mac lock${GRAY}: Lock"
            echo "${LIGHTBLUE}mac restart${GRAY}: Restart OS X"
            echo "${LIGHTBLUE}mac sleep${GRAY}: Sleep mode"
            echo "${LIGHTBLUE}mac shutdown${GRAY}: Shutdown"
            echo "${LIGHTBLUE}mac uptime${GRAY}: Get the time since last restart"
            echo "${LIGHTBLUE}mac volume${GRAY}: Get the volume from the terminal"
            echo "${LIGHTBLUE}mac volume ${LIGHTGREEN}X${GRAY}: Set the volume from the terminal - ${LIGHTGREEN}X = Level (0-100)"
            echo "${LIGHTBLUE}mac volume:mute${GRAY}: Mute volume"
            echo "${LIGHTBLUE}mac volume:unmute${GRAY}: Unmute volume"
            echo "${LIGHTBLUE}mac volume:ismute${GRAY}: Check if the volume is muted or not"
            echo "${LIGHTBLUE}mac screensaver${GRAY}: Start screensaver"
            echo "${LIGHTBLUE}mac folders:list${GRAY}: List folders in current directory with their current size"
            echo "${LIGHTBLUE}mac folder:size${GRAY}: Calculate current folder size"
            echo "${LIGHTBLUE}mac dock:add-space ${LIGHTGREEN}N${GRAY}: Add blank space to dock - ${LIGHTGREEN}N = Number of spaces to add"
            echo "${LIGHTBLUE}mac eject-all${GRAY}: Eject all mounted volumes and disks"
            echo "${LIGHTBLUE}mac battery${GRAY}: Get battery information"
            echo "${LIGHTBLUE}mac info${GRAY}: Get OS X version information"
            echo "${LIGHTBLUE}mac find:text ${LIGHTGREEN}X${GRAY}: Find exact phrase recursively inside directory - ${LIGHTGREEN}X = Text string"
            echo "${LIGHTBLUE}mac find:biggest-files ${GRAY}: Find biggest files inside directory"
            echo "${LIGHTBLUE}mac find:biggest-directories ${GRAY}: Find biggest directories inside directory"
            echo "${LIGHTBLUE}mac zip:extract ${LIGHTGREEN}X${GRAY}: Extract Zip file to current folder - ${LIGHTGREEN}X = Zip file to extract"
            echo "${LIGHTBLUE}mac gzip:compress ${LIGHTGREEN}X${GRAY}: Compress current file using Gzip - ${LIGHTGREEN}X = File to compress"
            echo "${LIGHTBLUE}mac gzip:extract ${LIGHTGREEN}X${GRAY}: Extract Gzip file to current folder - ${LIGHTGREEN}X = Gzip file to extract"
            echo "${LIGHTBLUE}mac tar:compress ${LIGHTGREEN}X${GRAY}: Compress X file/directory using tar with progress indicator - ${LIGHTGREEN}X = File or directory"
            echo "${LIGHTBLUE}mac tar:extract ${LIGHTGREEN}X${GRAY}: Extract tar file to current folder - ${LIGHTGREEN}X = Tar file to extract"
            echo "${NC}\n"
            ;;
        search)
            echo "\n${WHITEBOLD}Search Utilities: "
            echo "${LIGHTBLUE}mac find:recent ${LIGHTGREEN}X${GRAY}: Find files modified in the last N minutes - ${LIGHTGREEN}X = number of minutes "
            echo "${LIGHTBLUE}mac search:replace ${LIGHTGREEN}X${GRAY}: Search and replace string in file - ${LIGHTGREEN}X = File to perform the search and replace operation"
            echo "${NC}\n"
            ;;
        network)
            echo "\n${WHITEBOLD}Network Utilities: "
            echo "${LIGHTBLUE}mac speedtest${GRAY}: Internet connection speed test "
            echo "${LIGHTBLUE}mac ports${GRAY}: List of used ports "
            echo "${LIGHTBLUE}mac ip:local${GRAY}: Get local IP address "
            echo "${LIGHTBLUE}mac ip:public${GRAY}: Get public IP address "
            echo "${NC}\n"
            ;;
        dns)
            echo "\n${WHITEBOLD}DNS Utilities: "
            echo "${LIGHTBLUE}mac dns:list${GRAY}: List DNS server(s) "
            echo "${LIGHTBLUE}mac dns:add${GRAY}: Add DNS server "
            echo "${LIGHTBLUE}mac dns:remove${GRAY}: Remove DNS server "
            echo "${LIGHTBLUE}mac dns:flush${GRAY}: Flush DNS cache "
            echo "${NC}\n"
            ;;
        ssh)
            echo "\n${WHITEBOLD}SSH Utilities: "
            echo "${LIGHTBLUE}mac ssh:download-file ${LIGHTGREEN}X${GRAY}: Download file from remote server through SSH - X = Path of the remote file to download "
            echo "${LIGHTBLUE}mac ssh:download-folder ${LIGHTGREEN}X${GRAY}: Download entire folder from remote server through SSH - X = Path of the remote folder to download "
            echo "${LIGHTBLUE}mac ssh:sync:local ${LIGHTGREEN}X${GRAY}: Sync local folder with remote folder using rsync through SSH (download remote folder to local folder)"
            echo "${LIGHTBLUE}mac ssh:sync:remote ${LIGHTGREEN}X${GRAY}: Path of the remote folder to sync from local folder (upload local folder to remote folder) "
            echo "${LIGHTBLUE}mac ssh:upload ${LIGHTGREEN}X${GRAY}: Upload file to remote server through SSH - X = Path of the file to upload to the remote server "
            echo "${LIGHTBLUE}mac ssh:public-key ${LIGHTGREEN}X${GRAY}: Get public SSH key for local machine "
            echo "${NC}\n"
            ;;
        performance)
            echo "\n${WHITEBOLD}Performance and maintenance Utilities: "
            echo "${LIGHTBLUE}mac system${GRAY}: Show system information to review mac performance "
            echo "${LIGHTBLUE}mac temp${GRAY}: Show temperature, fan and battery statistics "
            echo "${LIGHTBLUE}mac memory${GRAY}: See memory usage sorted by memory consumption "
            echo "${LIGHTBLUE}mac trash:empty${GRAY}: Empty trash"
            echo "${LIGHTBLUE}mac trash:size${GRAY}: Calculate trash size"
            echo "${NC}\n"
            ;;
        git)
            echo "\n${WHITEBOLD}Git Utilities: "
            echo "${LIGHTBLUE}mac git:config${GRAY}: Display local Git configuration "
            echo "${LIGHTBLUE}mac git:open${GRAY}: Open current repository on Github "
            echo "${LIGHTBLUE}mac git:create:branch${GRAY}: Create branch based on current branch "
            echo "${LIGHTBLUE}mac git:branches:date${GRAY}: Get last update date for all branches in current project "
            echo "${LIGHTBLUE}mac git:undo-commit${GRAY}: Undo latest commit "
            echo "${LIGHTBLUE}mac git:log${GRAY}: See latest commits IDs and titles for current branch "
            echo "${LIGHTBLUE}mac git:branch${GRAY}: See all branches "
            echo "${LIGHTBLUE}mac git:branch:rename${GRAY}: Rename Git branch "
            echo "${LIGHTBLUE}mac git:branch:remove-local${GRAY}: Remove local Git branch "
            echo "${LIGHTBLUE}mac git:branch:remove-remote${GRAY}: Remove local and remote Git branch "
            echo "${LIGHTBLUE}mac git:branch${GRAY}: See all branches "
            echo "${LIGHTBLUE}mac git:add-removed${GRAY}: Add removed files to staged files "
            echo "${LIGHTBLUE}mac git:size${GRAY}: Get size for current Git repository "
            echo "${NC}\n"
            ;;
        homebrew)
            echo "\n${WHITEBOLD}Homebrew Utilities: "
            echo "${LIGHTBLUE}mac brew:update${GRAY}: Upgrade Homebrew, installed Homebrew packages, and cleanup "
            echo "${NC}\n"
            ;;
    esac

}


case ${fn} in
    "list"|"help"|"usage")
        echo "$(printInfo)"
        for c in ${MacCategories[@]}
        do
            echo "$(usageList ${c})"
        done
        echo "$(printAdditionalHelp)"
        ;;
    "categories")
        echo "$(printInfo)"
        echo "\n${WHITEBOLD}mac CLI Categories: ${NC}\n"
        for c in "${MacCategories[@]}"
        do
            echo "${WHITEBOLD} >\t$c ${NC}"
        done
        echo "$(printAdditionalHelp)"
        ;;
esac

for c in "${MacCategories[@]}"
do
    if [ "${c}" = "${fn}" ]; then
        echo "$(printInfo)"
        echo "\n${WHITEBOLD}Usage for 'mac ${c}'"
        echo "$(usageList ${c})"
        break
    fi
done


================================================
FILE: mac-cli/plugins/brew
================================================
#!/bin/sh

#--------------------------------------------------------------------
# Homebrew Utilities
#--------------------------------------------------------------------

case "$fn" in

    # Update Homebrew and installed packages
    "brew:update")
        echo "Updating Homebrew and its installed packages..."
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}brew update; brew upgrade;  brew upgrade --cask; brew cleanup;\n${NC}"
        fi
        brew update; brew upgrade;  brew upgrade --cask; brew cleanup;
    ;;

esac


================================================
FILE: mac-cli/plugins/dns
================================================
#!/bin/sh

#--------------------------------------------------------------------
# DNS Utilities
#--------------------------------------------------------------------

case "$fn" in

    # List DNS server(s)
    "dns:list")
        echo "List of the DNS server(s):"
        cat /etc/resolv.conf | grep nameserver | cut -b 11-
    ;;

    # Add DNS server
    "dns:add")
        if [[ $2 =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]
        then
            echo "Adding DNS server $2"
            sudo sh -c "echo nameserver '${2}' >> /etc/resolv.conf"
        else
            echo "Please provide a valid DNS server address to add."
            exit 1
        fi
    ;;

    # Remove DNS server
    "dns:remove")
        if [[ $2 =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]
        then
            echo "Deleting DNS server ${2}..."
            sudo sed -i "" "/${2}/d" /etc/resolv.conf
        else
            echo "Please provide a valid DNS server address to remove."
            exit 1
        fi
    ;;

    # Flush DNS cache
    "dns:flush")
        VERSION=$(sw_vers -productVersion)
        echo "Flushing DNS cache..."
        if echo $VERSION | grep -E '^10\.10(\.[0-3])?$' >/dev/null 2>&1; then
            sudo discoveryutil mdnsflushcache
        elif echo $VERSION | grep -E '^10\.6(\.[0-8])?$' >/dev/null 2>&1; then
            sudo dscacheutil -flushcache
        else
            sudo killall -HUP mDNSResponder
        fi
    ;;

esac

================================================
FILE: mac-cli/plugins/general
================================================
#!/bin/sh

#--------------------------------------------------------------------
# General Variables
#--------------------------------------------------------------------

_W_DEVICE=${_W_DEVICE:-en0}

#--------------------------------------------------------------------
# General Utilities
#--------------------------------------------------------------------

case "$fn" in

    # Install macOS software updates, update installed Ruby gems, Homebrew, npm, pip and their installed packages
    "update")

        echo "Updating macOS..."
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}sudo softwareupdate -i -a;\n${NC}"
        fi
        sudo softwareupdate -i -a;

        echo "Updating Homebrew and its installed packages..."
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}brew update; brew upgrade;  brew upgrade --cask; brew cleanup; \n${NC}"
        fi
        brew update; brew upgrade;  brew upgrade --cask; brew cleanup;

        echo "Updating npm and its installed packages..."
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}npm install npm -g; npm update -g;\n${NC}"
        fi
        npm install npm -g; npm update -g;

        echo "Updating Yarn's installed packages..."
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}yarn global upgrade;\n${NC}"
        fi
        yarn global upgrade;

        echo "Updating installed Ruby gems..."
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}sudo gem update --system; sudo gem update\n${NC}"
        fi
        sudo gem update --system; sudo gem update

        echo "Updating installed pip packages..."
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}pip list --outdated --local | tail -n +3 | awk '{print \$1}' | xargs -n1 pip install -U\n${NC}"
        fi
        pip list --outdated --local | tail -n +3 | awk '{print $1}' | xargs -n1 pip install -U

        if [ -x "$(command -v pip3)" ]; then
            echo "Updating installed pip3 packages..."
            if [ "$echocommand" == "true" ]; then
                echo "${GREEN}pip3 list --outdated --local | tail -n +3 | awk '{print \$1}' | xargs -n1 pip3 install -U\n${NC}"
            fi
            pip3 list --outdated --local | tail -n +3 | awk '{print $1}' | xargs -n1 pip3 install -U
        fi

        if [ -f /usr/local/bin/apm ]; then
            echo "Updating Atom Packages..."
            if [ "$echocommand" == "true" ]; then
                echo "${GREEN}apm upgrade --no-confirm\n${NC}"
            fi
            apm upgrade --no-confirm
        fi
    ;;


    # Upgrade Mac CLI to the latest version
    "upgrade")
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}sh -c "$(curl -fsSL https://raw.githubusercontent.com/guarinogabriel/mac-cli/master/mac-cli/tools/update)"\n\n${NC}"
        fi
        sh -c "$(curl -fsSL https://raw.githubusercontent.com/guarinogabriel/mac-cli/master/mac-cli/tools/update)"
    ;;


    # Uninstall Mac CLI from your Mac
    "uninstall")
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}sh -c "$(curl -fsSL https://raw.githubusercontent.com/guarinogabriel/mac-cli/master/mac-cli/tools/uninstall)"\n\n${NC}"
        fi
        sh -c "$(curl -fsSL https://raw.githubusercontent.com/guarinogabriel/mac-cli/master/mac-cli/tools/uninstall)"
    ;;


    # Get macOS Info
    "info")
        printf "${GREEN}sw_vers\n${NC}"
        sw_vers
    ;;


    # Lock Mac
    "lock")
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend\n\n${NC}"
        fi
        /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
    ;;


    # Restart Mac
    "restart")
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}osascript -e 'tell app 'loginwindow' to «event aevtrrst»''\n\n${NC}"
        fi
        osascript -e 'tell app "loginwindow" to «event aevtrrst»'
    ;;


    # Sleep
    "sleep")
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}pmset sleepnow\n\n${NC}"
        fi
        pmset sleepnow
    ;;


    # Shutdown Mac
    "shutdown")
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}osascript -e 'tell app 'loginwindow' to «event aevtrsdn»'\n\n${NC}"
        fi
        osascript -e 'tell app "loginwindow" to «event aevtrsdn»'
    ;;

    # Uptime
    "uptime")
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}uptime\n\n${NC}"
        fi
        uptime
    ;;


    #List folders in current directory
    "folders:list")
        du -sk * | sort -rn
    ;;


    # Calculate folder size
    "folder:size")
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}du -sh .\n\n${NC}"
        fi
        echo "Calculating folder size..."
        echo "Folder size:"
        du -sh .
    ;;


    # Show hidden files
    "hidden:show")
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}defaults write com.apple.finder AppleShowAllFiles YES; killall Finder\n\n${NC}"
        fi
        defaults write com.apple.finder AppleShowAllFiles YES; killall Finder
    ;;


    # Hide hidden files
    "hidden:hide")
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}defaults write com.apple.finder AppleShowAllFiles NO; killall Finder\n\n${NC}"
        fi
        defaults write com.apple.finder AppleShowAllFiles NO; killall Finder
    ;;


    # Check bluetooth status
    "bluetooth:status")
        defaults read /Library/Preferences/com.apple.Bluetooth ControllerPowerState | \
            awk '{ if($1 != 0) {print "Bluetooth: ON"} else { print "Bluetooth: OFF" }  }'
    ;;


    # Enable bluetooth
    "bluetooth:enable")
        echo "${GREEN}Bluetooth enabled{NC}"
        sudo defaults write /Library/Preferences/com.apple.Bluetooth ControllerPowerState -int 1 && \
            sudo killall -HUP bluetoothd
    ;;


    # Disable bluetooth
    "bluetooth:disable")
        echo "${GREEN}Bluetooth disabled${NC}"
        sudo defaults write /Library/Preferences/com.apple.Bluetooth ControllerPowerState -int 0 && \
            sudo killall -HUP bluetoothd
    ;;


    # Check wifi status
    "wifi:status")
        /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I
    ;;


    # Check available wifi networks
    "wifi:scan")
        /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s
    ;;


    # Enable wifi
    "wifi:enable")
        echo "${GREEN}Wifi enabled${NC}"
        networksetup -setairportpower ${_W_DEVICE} on
    ;;


    # Disable wifi
    "wifi:disable")
        echo "${GREEN}Wifi disabled${NC}"
        networksetup -setairportpower ${_W_DEVICE} off
    ;;


    # Add blank space to the dock
    "dock:add-space")
        if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
          echo "${GREEN}Added $firstParameter new blank spaces to the dock${NC}"

          for i in `seq "$firstParameter"`; do
            defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}'
          done
        else
          echo "${GREEN}Added new blank space to the dock${NC}"
          defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}'
        fi

        killall Dock
    ;;


    # Start screensaver
    "screensaver")
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}open -a ScreenSaverEngine\n\n${NC}"
        fi
        open -a ScreenSaverEngine
    ;;


    # Eject all mounted volumes and disk
    "eject-all")
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}osascript -e 'tell application 'Finder' to eject (every disk whose ejectable is true)'\n\n${NC}"
        fi
        osascript -e 'tell application "Finder" to eject (every disk whose ejectable is true)'
    ;;


    # Get battery information
    "battery")
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}pmset -g batt\n\n${NC}"
        fi
        pmset -g batt
    ;;


    # Find text in current directory
    "find:text")

        if [ ! -z "$allParameters" -a "$allParameters" != " " ]; then
            echo "Please enter the extension to search (i.e.: csv): "

            read extension

            if [ ! -z "$extension" -a "$extension" != " " ]; then

                if [ "$echocommand" == "true" ]; then
                    echo "${GREEN}find . -iname '*.${GRAY}${extension}${GREEN}' | xargs grep -in --color '${GRAY}${allParameters}${GREEN}'${NC}"
                fi
                echo "\nRecursively find '"$allParameters"' inside directory..."
                find . -iname "*.$extension" | xargs grep -in --color "$allParameters"

            else
                echo "Please introduce the extension of the files to search. E.g: csv"
            fi
        else
            echo "Please introduce text to search. E.g:"
            echo "mac find:text Sample Search Text"
        fi
    ;;


    # Find biggest files in current directory
    "find:biggest-files")
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}find . -type f -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}${NC}"
        fi
        find . -type f -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
    ;;


    # Find biggest directories in current directory
    "find:biggest-directories")
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}find . -type d -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}${NC}"
        fi
        find . -type d -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
    ;;


    # Extract Zip file
    "zip:extract")

        if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
            if [ "$echocommand" == "true" ]; then
                echo "${GREEN}unzip ${GRAY}${firstParameter}\n\n${NC}"
            fi
            unzip $firstParameter
        else
            echo "Please specify the Zip file to extract."
            echo "E.g.: zip:extract sample_file.zip"
        fi
    ;;


    # Compress Gzip file
    "gzip:compress")

        if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
            if [ "$echocommand" == "true" ]; then
                echo "${GREEN}gzip ${GRAY}${firstParameter}\n\n${NC}"
            fi
            gzip $firstParameter
        else
            echo "Please specify the file to compress."
            echo "E.g.: gzip:compress sample_file"
        fi
    ;;


    # Extract Gzip file
    "gzip:extract")

        if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
            if [ "$echocommand" == "true" ]; then
                echo "${GREEN}gzip -d ${GRAY}${firstParameter}\n\n${NC}"
            fi
            gzip -d $firstParameter
        else
            echo "Please specify the Gzip file to extract."
            echo "E.g.: gzip:extract sample_file.gz"
        fi
    ;;


    # Extract tar file
    "tar:extract")

        if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
            if [ "$echocommand" == "true" ]; then
                echo "${GREEN}tar -xvzf ${GRAY}${firstParameter}\n\n${NC}"
            fi
            tar -xvzf $firstParameter
        else
            echo "Please specify the tar file to extract."
            echo "E.g.: tar:extract sample_file.tgz"
	    fi
    ;;


    # Compress file/folder using TAR with progress indicator
    "tar:compress")
        echo "Please enter the filename to save the .tgz file: "

        if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
            read filename

            if [ ! -z "$filename" -a "$filename" != " " ]; then
                if [ "$echocommand" == "true" ]; then
                    echo "${GREEN}tar -czf${GRAY}: ${firstParameter}${GREEN}  | (pv -p --timer --rate --bytes > '${GRAY}${filename}${GREEN}'.tgz)\n\n${NC}"
                fi
                tar -czf - $firstParameter | (pv -p --timer --rate --bytes > "$filename".tgz)
            else
                "Please specify the file name"
            fi
        else
            echo "Please specify the folder or directory to compress."
            echo "E.g.: tar:compress foldername"
        fi
    ;;


    # Search and replace string on file
    "search:replace")
        echo "Please enter the string to search on the file:"

        if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
            read searchString

            if [ ! -z "$searchString" -a "$searchString" != " " ]; then

                echo "Please enter the string that will replace the search string:"
                read replaceString

                if [ ! -z "$replaceString" -a "$replaceString" != " " ]; then

                    if [ "$echocommand" == "true" ]; then
                        echo "${GREEN}LC_CTYPE=C sed -i'' -e 's#${GRAY}${searchString}${GREEN}#${GRAY}${replaceString}${GREEN}#g' ${GRAY}${firstParameter}\n\n${NC}"
                    fi
                    LC_CTYPE=C sed -i'' -e 's#'"${searchString}"'#'"${replaceString}"'#g' $firstParameter

                else
                    "Please specify the string to replace"
                fi

            else
                "Please specify the string to search"
            fi
        else
            echo "Please specify the file to perform the search and replace operation"
            echo "E.g.: search:replace /path/to/file.csv"
        fi
    ;;


esac


================================================
FILE: mac-cli/plugins/git
================================================
#!/bin/sh

#--------------------------------------------------------------------
# Git Utilities
#--------------------------------------------------------------------

case "$fn" in

    # Display local Git configuration
    "brew:git:config")

        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}git config --list\n\n${NC}"
        fi
        git config --list
    ;;


    # Open current Git repository on Github
    "git:open")

        giturl=$(git config --get remote.origin.url)
          if [ "$giturl" == "" ]
            then
             echo "Not a git repository or no remote.origin.url set"
             exit 1;
          fi
          giturl=${giturl/git\@github\.com\:/https://github.com/}
          giturl=${giturl/\.git/\/}
          branch="$(git symbolic-ref HEAD 2>/dev/null)" ||
          branch="(unnamed branch)"     # detached HEAD
          branch=${branch##refs/heads/}
          giturl=$giturl
          open $giturl
    ;;


    # Create Git branch based on current branch
    "git:create:branch")

        if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
            if [ "$echocommand" == "true" ]; then
                echo "${GREEN}git checkout -b ${GRAY}$firstParameter\n\n${NC}"
            fi
            git checkout -b $firstParameter

        else
            echo "Please specify the name for the new branch"
            echo "E.g.: git:create:branch sample-branch"
        fi
    ;;


    # Get last update date for all branches in current project
    "git:branches")

        git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
    ;;


    # Undo latest commit
    "git:undo-commit")

        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}git reset --soft HEAD~\n\n${NC}"
        fi
        git reset --soft HEAD~
    ;;


    # See latest commits IDs and titles for current branch
    "git:log")

        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}git log --pretty=oneline\n\n${NC}"
        fi
    	git log --pretty=oneline
    ;;


    # See all branches
    "git:branch")

        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}git branch -a\n\n${NC}"
        fi
        git branch -a
    ;;


    # Rename Git branch
    "git:branch:rename")

         if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
            if [ "$echocommand" == "true" ]; then
                echo "${GREEN}git branch -m ${GRAY}$firstParameter\n\n${NC}"
            fi
            git branch -m $firstParameter

        else
            echo "Please specify the name of the branch to rename"
            echo "E.g.: git:branch:rename sample-branch"
        fi
    ;;


    # Remove local Git branch
    "git:branch:remove-local")

         if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
            if [ "$echocommand" == "true" ]; then
                echo "${GREEN}git branch -d ${GRAY}$firstParameter\n\n${NC}"
            fi
            git branch -d $firstParameter

        else
            echo "Please specify the name of the branch to remove"
            echo "E.g.: git:branch:remove-local sample-branch"
        fi
    ;;


    # Remove local and remote Git branch
    "git:branch:remove-remote")

         if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
            if [ "$echocommand" == "true" ]; then
                echo "${GREEN}git branch -d ${GRAY}$firstParameter\n\n${NC}"
            fi
            git branch -d $firstParameter
            if [ "$echocommand" == "true" ]; then
                echo "${GREEN}git push origin --delete ${GRAY}$firstParameter\n\n${NC}"
            fi
            git push origin --delete $firstParameter

        else
            echo "Please specify the name of the branch to remove"
            echo "E.g.: git:branch:remove-remote sample-branch"
        fi
    ;;


    # Check Git settings
    "git:config")

        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}git config --list\n\n${NC}"
        fi
        git config --list
    ;;


    # Add removed files to staged files
    "git:add-removed")

        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}git add -u\n\n${NC}"
        fi
        git add -u
    ;;


    # Open current Git repository URL
    "git:open")

        open `git remote -v | awk '/fetch/{print $2}' | sed -Ee 's#(git@|git://)#http://#' -e 's@com:@com/@'`| head -n1
    ;;


    # Get size of current Git repository
    "git:size")

        git bundle create tmp.bundle --all
        echo "\n\nCurrent Git repository size: "
        du -sh tmp.bundle
        rm tmp.bundle
    ;;


esac

================================================
FILE: mac-cli/plugins/network
================================================
#!/bin/sh

#--------------------------------------------------------------------
# Network Utilities
#--------------------------------------------------------------------

case "$fn" in

    # Internet connection speed test
    "speedtest")
          echo "Testing internet connection speed..."
          networkQuality -v
    ;;


    # List of used ports
    "ports")

        echo "Getting list of used ports..."
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}sudo lsof -iTCP -sTCP:LISTEN -P\n\n${NC}"
        fi
        sudo lsof -iTCP -sTCP:LISTEN -P
    ;;


    # Get local IP address
    "ip:local")

        local_ip=$(ipconfig getifaddr en0)
        if [ $? == 0 ]; then
            if [ "$echocommand" == "true" ]; then
                echo "${GREEN}ipconfig getifaddr en0\n\n${NC}"
            fi
        else
            if [ "$echocommand" == "true" ]; then
                echo "${GREEN}ipconfig getifaddr en1\n\n${NC}"
            fi
            local_ip=$(ipconfig getifaddr en1)
        fi
        echo "Your IP address is:\n${local_ip}"
    ;;


    # Get public IP address
    "ip:public")

        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}wget http://ipinfo.io/ip -qO -\n\n${NC}"
        fi
        wget http://ipinfo.io/ip -qO -
    ;;

esac


================================================
FILE: mac-cli/plugins/performance
================================================
#!/bin/sh

#--------------------------------------------------------------------
# Performance and maintenance Utilities
#--------------------------------------------------------------------

case "$fn" in

    # See memory usage sorted by memory consumption
    "memory")

        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}top -o MEM \n\n${NC}"
        fi
        top -o MEM
    ;;


    # Empty trash
    "trash:empty")

        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}sudo rm -rf ~/.Trash/* \n\n${NC}"
        fi
        sudo rm -rf ~/.Trash/*
    ;;


    # Calculate trash size
    "trash:size")

        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}du -sh ~/.Trash/ \n\n${NC}"
        fi
        echo "Trash size: "
        du -sh ~/.Trash/
    ;;

esac

================================================
FILE: mac-cli/plugins/search
================================================
#!/bin/sh

#--------------------------------------------------------------------
# Search Utilities
#--------------------------------------------------------------------

case "$fn" in

    # Find files modified in the last N minutes
    "find:recent")

        echo "Searching for files modified in the last "$firstParameter" minutes..."
        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}sudo find / -mmin ${GRAY}${firstParameter}${GREEN} -type f\n\n${NC}"
        fi
        sudo find / -mmin $firstParameter -type f
    ;;

esac

================================================
FILE: mac-cli/plugins/ssh
================================================
#!/bin/sh

#--------------------------------------------------------------------
# SSH Utilities
#--------------------------------------------------------------------

case "$fn" in

    # Download file through SSH on current folder
    "ssh:download-file")

        if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then

            echo "Please enter the server IP address or domain: "

            read ipaddress
            if [ ! -z "$ipaddress" -a "$ipaddress" != " " ]; then

                echo "Please enter username: "

                read username

                if [ ! -z "$username" -a "$username" != " " ]; then

                    if [ "$echocommand" == "true" ]; then
                        echo "${GREEN}scp ${GRAY}${username}@${ipaddress}:${firstparameter}${GREEN} .\n\n${NC}"
                    fi
                    scp $username@$ipaddress:$firstParameter .

                else
                    "Please specify the username for the remote server"
                fi

            else
                "Please specify the server IP address or domain"
            fi

        else
            echo "Please specify the path to the file on the remote server to download"
            echo "E.g.: /home/sample/file.jpg"
        fi
    ;;


    # Download entire folder through SSH on current directory
    "ssh:download-folder")

        if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then

            echo "Please enter the server IP address or domain: "

            read ipaddress
            if [ ! -z "$ipaddress" -a "$ipaddress" != " " ]; then

                echo "Please enter username: "

                read username

                if [ ! -z "$username" -a "$username" != " " ]; then

                    if [ "$echocommand" == "true" ]; then
                        echo "${GREEN}scp -r ${GRAY}${username}@${ipaddress}:${firstparameter}${GREEN} .\n\n${NC}"
                    fi
                    scp -r $username@$ipaddress:$firstParameter .

                else
                    "Please specify the username for the remote server"
                fi

            else
                "Please specify the server IP address or domain"
            fi

        else
            echo "Please specify the path to the folder on the remote server to download"
            echo "E.g.: /home/sample/folder/"
        fi
    ;;


    # Sync local folder with remote folder using rsync through SSH (download remote folder to local folder)
    "ssh:sync:local")

        if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then

            echo "Please enter the server IP address or domain: "

            read ipaddress
            if [ ! -z "$ipaddress" -a "$ipaddress" != " " ]; then

                echo "Please enter username: "

                read username

                if [ ! -z "$username" -a "$username" != " " ]; then

                    echo "Please enter local folder to sync with the remote folder: "

                    read localfolder

                    if [ ! -z "$localfolder" -a "$localfolder" != " " ]; then
                        if [ "$echocommand" == "true" ]; then
                            echo "${GREEN}rsync -a --progress ${GRAY}${username}@${ipaddress}:${firstparameter} ${localfolder}${GREEN}\n\n${NC}"
                        fi
                        rsync -a --progress ${username}@${ipaddress}:${firstparameter} ${localfolder}

                    else
                        "Please specify the local folder to sync with the remote folder"
                    fi
                else
                    "Please specify the username for the remote server"
                fi

            else
                "Please specify the server IP address or domain"
            fi

        else
            echo "Please specify the remote folder path to sync"
            echo "E.g.: mac ssh:sync:remote /var/www/html/media/"
        fi
    ;;


    # Sync remote folder with local folder using rsync through SSH (upload local folder to remote folder)
    "ssh:sync:remote")

        if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then

            echo "Please enter the server IP address or domain: "

            read ipaddress
            if [ ! -z "$ipaddress" -a "$ipaddress" != " " ]; then

                echo "Please enter username: "

                read username

                if [ ! -z "$username" -a "$username" != " " ]; then

                    echo "Please enter local folder to sync from the remove folder: "

                    read localfolder

                    if [ ! -z "$localfolder" -a "$localfolder" != " " ]; then
                        if [ "$echocommand" == "true" ]; then
                            echo "${GREEN}rsync -a ${localfolder} ${username}@${ipaddress}:${firstparameter}\n\n${NC}"
                        fi
                        rsync -a --progress ${localfolder} ${username}@${ipaddress}:${firstparameter}

                    else
                        "Please specify the local folder to sync from the remote folder"
                    fi
                else
                    "Please specify the username for the remote server"
                fi

            else
                "Please specify the server IP address or domain"
            fi

        else
            echo "Please specify the remote folder path to sync"
            echo "E.g.: mac ssh:sync:remote /var/www/html/media/"
        fi
    ;;


    # Upload file to remote server through SSH
    "ssh:upload")

        if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then

            echo "Please enter the server IP address or domain: "

            read ipaddress

            if [ ! -z "$ipaddress" -a "$ipaddress" != " " ]; then

                echo "Please enter username: "

                read username

                if [ ! -z "$username" -a "$username" != " " ]; then

                        echo "Please enter path on the remote server to upload the file: "

                        read remotePath

                        if [ ! -z "$remotePath" -a "$remotePath" != " " ]; then

                            if [ "$echocommand" == "true" ]; then
                                echo "${GREEN}scp ${GRAY}${firstParameter} ${username}@${ipaddress}:${remotePath}${GREEN}\n\n${NC}"
                            fi
                            scp $firstParameter $username@$ipaddress:$remotePath

                        else
                            "Please specify the path on the remote server to upload the file"
                        fi

                else
                    "Please specify the username for the remote server"
                fi

            else
                "Please specify the server IP address or domain"
            fi

        else
            echo "Please specify the path to the file to upload to the remote server"
            echo "E.g.: /user/example/documents/file.pdf"
        fi
    ;;


    # SSH key Utilities
    "ssh:public-key")

        if [ "$echocommand" == "true" ]; then
            echo "${GREEN}pbcopy < ~/.ssh/id_rsa.pub \n\n${NC}"
        fi
        pbcopy < ~/.ssh/id_rsa.pub
    ;;


esac

================================================
FILE: mac-cli/plugins/volume
================================================
#!/bin/sh

#--------------------------------------------------------------------
# Volume Utilities
#--------------------------------------------------------------------

case "$fn" in

    # Get current volume
    "volume")
        if [ ! -z "$firstParameter" -a "$firstParameter" != " " ]; then
            osascript -e "set volume output volume $firstParameter"
            echo "${WHITEBOLD}Vol:${NC} ${GREEN}${firstParameter}%${NC}"
        else
            echo "${WHITEBOLD}Vol:${NC} ${GREEN}$(osascript -e "output volume of (get volume settings)")% ${NC}"

        fi
    ;;

     # Is volume muted?
    "volume:ismute")
        echo "${WHITEBOLD}Mute:${NC} ${GREEN}$(osascript -e 'output muted of (get volume settings)')${NC}"
    ;;

     # Mute volume
    "volume:mute")
        osascript -e "set volume output muted true"
        echo "${WHITEBOLD}Mute:${NC} ${GREEN}true${NC}"
    ;;

     # Unmute volume
    "volume:unmute")
        osascript -e "set volume output muted false"
        echo "${WHITEBOLD}Mute:${NC} ${GREEN}false${NC}"
    ;;

esac


================================================
FILE: mac-cli/tools/install
================================================
#!/bin/sh

# Colors
GREEN='\033[0;32m'
LIGHTGREEN='\033[1;32m'
NC='\033[1;37m'
LIGHTBLUE='\033[01;34m'
NC='\033[0m' # No Color

# In directory
PACKAGE_DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
suggest_current(){
    case "$1" in
        "editor")
            current=$EDITOR
        ;;
        *)
            current=$(which $1)
        ;;
    esac
    if [ -n $current ]; then
        echo $current | pbcopy
        echo "${NC}Press ⌘V to insert current (${current})"
    fi
}

main() {

    echo "${LIGHTBLUE}================================================"
    echo " Mac CLI Installer"
    echo "================================================${NC}\n"

    git clone https://github.com/guarinogabriel/mac-cli.git --depth 1 && cd mac-cli

    printf "${LIGHTGREEN}"
    read -r -p "Would you like Mac CLI to show you the commands that are run on each mac command? (Yes / No)" response
    case $response in
        [yY][eE][sS]|[yY])
            LC_CTYPE=C sed -i'' -e 's#echocommand="false"#echocommand="true"#g' "$PACKAGE_DIRECTORY/mac-cli/mac"
            ;;
        *)
            ;;
    esac
    printf "${NC}"

    sudo cp "$PACKAGE_DIRECTORY/mac-cli/mac" /usr/local/bin/mac
    sudo cp -r "$PACKAGE_DIRECTORY/mac-cli/mac-cli/" /usr/local/bin/mac-cli
    sudo chmod -R +x /usr/local/bin/mac-cli/*

    if ! [ -x "$(command -v brew)" ]; then
        echo "Installing Homebrew..."
        echo "${GREEN}/usr/bin/ruby -e '\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)'\n${NC}"
        /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    fi

    if ! [ -x "$(command -v git)" ]; then
        echo "Installing Git..."
        echo "${GREEN}brew install git\n${NC}"
        brew install git
	  fi

    if ! [ -x "$(command -v pv)" ]; then
        echo "Installing pv (Pipe Viewer)..."
        echo "${GREEN}brew install pv\n${NC}"
        brew install pv
	  fi

    if ! [ -x "$(command -v wget)" ]; then
        echo "Installing wget..."
        printf "${GREEN}brew install wget\n${NC}"
        brew install wget
	  fi

    if ! brew list | grep -q bash-completion ; then

            echo "Installing bash-completion\n"
            echo "${GREEN}brew install bash-completion\n\n${NC}"
            brew install bash-completion
            echo 'if [ -f $(brew --prefix)/etc/bash_completion ]; then source $(brew --prefix)/etc/bash_completion; fi' >> ~/.bashrc
            echo "Setting up Mac-CLI bash-completion\n"

        if [ -d /usr/local/etc/bash_completion.d/ ]; then
            cp /usr/local/bin/mac-cli/completion/bash_completion /usr/local/etc/bash_completion.d/mac
        fi

    else

        echo "Setting up Mac-CLI bash-completion\n"

        if [ -d $(brew --prefix)/etc/bash_completion.d/ ]; then
            cp /usr/local/bin/mac-cli/completion/bash_completion $(brew --prefix)/etc/bash_completion.d/mac
            echo 'if [ -f $(brew --prefix)/etc/bash_completion ]; then source $(brew --prefix)/etc/bash_completion; fi' >> ~/.bashrc
        fi

    fi

    #
    # Check if fish shell is installed and prompt user to copy fish_completion
    #
    if $(cat /etc/shells | grep -q fish) && [ -d ~/.config/fish ];
    then
	    printf "${LIGHTGREEN}"
	    read -r -p "Would you like to install fish shell suggestions/tab completion? (Yes / No) " response
	    case $response in
		    [yY][eE][sS]|[yY])
			    echo "Setting up Mac-CLI Fish completion"
			    if [ -d ~/.config/fish/completions ];then
				    cp /usr/local/bin/mac-cli/completion/fish_completion ~/.config/fish/completions/mac.fish
			    else
				    mkdir ~/.config/fish/completions && cp /usr/local/bin/mac-cli/completion/fish_completion ~/.config/fish/completions/mac.fish
			    fi
			    ;;
		    *)
			    ;;
	    esac
	    printf "${NC}"
    fi
}

main


================================================
FILE: mac-cli/tools/uninstall
================================================
#!/bin/sh

GREEN='\033[0;32m'
NC='\033[0m' # No Color

main() {
  echo "Uninstalling Mac CLI..."
	rm /usr/local/bin/mac
	rm -rf /usr/local/bin/mac-cli
	echo "${GREEN}Mac CLI has been uninstalled\n${NC}"
}

main

================================================
FILE: mac-cli/tools/update
================================================
#!/bin/sh

GREEN='\033[0;32m'
NC='\033[0m' # No Color

main() {
  echo "Upgrading Mac CLI..."
	rm /usr/local/bin/mac
	rm -rf /usr/local/bin/mac-cli
	if [ -d ~/Downloads/mac-cli-update/ ]; then
	    rm -rf ~/Downloads/mac-cli-update/
	fi
	mkdir ~/Downloads/mac-cli-update/ && cd ~/Downloads/mac-cli-update/
	sh -c "$(curl -fsSL https://raw.githubusercontent.com/guarinogabriel/mac-cli/master/mac-cli/tools/install)" && cd -
	echo "${GREEN}Mac CLI has been updated to the latest version\n${NC}"
}

main
Download .txt
gitextract_i2r9ry5d/

├── .github/
│   └── stale.yml
├── .gitignore
├── LICENSE.md
├── README.md
├── mac
└── mac-cli/
    ├── completion/
    │   ├── bash_completion
    │   └── fish_completion
    ├── misc/
    │   └── help
    ├── plugins/
    │   ├── brew
    │   ├── dns
    │   ├── general
    │   ├── git
    │   ├── network
    │   ├── performance
    │   ├── search
    │   ├── ssh
    │   └── volume
    └── tools/
        ├── install
        ├── uninstall
        └── update
Condensed preview — 20 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (64K chars).
[
  {
    "path": ".github/stale.yml",
    "chars": 684,
    "preview": "# Number of days of inactivity before an issue becomes stale\ndaysUntilStale: 60\n# Number of days of inactivity before a "
  },
  {
    "path": ".gitignore",
    "chars": 61,
    "preview": ".DS_Store\n.idea/\n.idea/workspace.xml\n.phpstorm.meta.php\n*.iml"
  },
  {
    "path": "LICENSE.md",
    "chars": 1064,
    "preview": "Copyright (c) 2015-2022 Gabriel Guarino\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of"
  },
  {
    "path": "README.md",
    "chars": 8140,
    "preview": "# Mac CLI\n\n macOS command line tools for developers\n\n\n---\n\n### Sponsors\n\n>[![Sponsor logo](images/sponsor-icon.png)](ht"
  },
  {
    "path": "mac",
    "chars": 4379,
    "preview": "#!/bin/sh\n###########################################################################\n#  mac CLI (mac command line tool"
  },
  {
    "path": "mac-cli/completion/bash_completion",
    "chars": 338,
    "preview": "# Mac_CLI bash completion\n\nhave mac && {\n_mac() {\n    local MACWORDS cur\n\n    COMPREPLY=()\n    _get_comp_words_by_ref -n"
  },
  {
    "path": "mac-cli/completion/fish_completion",
    "chars": 109,
    "preview": "complete -c mac -a (awk \"/COMMANDS=/,/#/\" < /usr/local/bin/mac  | tail -n +2 | sed '/)/d;/#/d' | tr -d '\\n')\n"
  },
  {
    "path": "mac-cli/misc/help",
    "chars": 8898,
    "preview": "#!/bin/sh\n\n#--------------------------------------------------------------------\n# mac script commands list - all comman"
  },
  {
    "path": "mac-cli/plugins/brew",
    "chars": 553,
    "preview": "#!/bin/sh\n\n#--------------------------------------------------------------------\n# Homebrew Utilities\n#-----------------"
  },
  {
    "path": "mac-cli/plugins/dns",
    "chars": 1445,
    "preview": "#!/bin/sh\n\n#--------------------------------------------------------------------\n# DNS Utilities\n#----------------------"
  },
  {
    "path": "mac-cli/plugins/general",
    "chars": 13726,
    "preview": "#!/bin/sh\n\n#--------------------------------------------------------------------\n# General Variables\n#------------------"
  },
  {
    "path": "mac-cli/plugins/git",
    "chars": 4865,
    "preview": "#!/bin/sh\n\n#--------------------------------------------------------------------\n# Git Utilities\n#----------------------"
  },
  {
    "path": "mac-cli/plugins/network",
    "chars": 1312,
    "preview": "#!/bin/sh\n\n#--------------------------------------------------------------------\n# Network Utilities\n#------------------"
  },
  {
    "path": "mac-cli/plugins/performance",
    "chars": 824,
    "preview": "#!/bin/sh\n\n#--------------------------------------------------------------------\n# Performance and maintenance Utilities"
  },
  {
    "path": "mac-cli/plugins/search",
    "chars": 553,
    "preview": "#!/bin/sh\n\n#--------------------------------------------------------------------\n# Search Utilities\n#-------------------"
  },
  {
    "path": "mac-cli/plugins/ssh",
    "chars": 7224,
    "preview": "#!/bin/sh\n\n#--------------------------------------------------------------------\n# SSH Utilities\n#----------------------"
  },
  {
    "path": "mac-cli/plugins/volume",
    "chars": 1063,
    "preview": "#!/bin/sh\n\n#--------------------------------------------------------------------\n# Volume Utilities\n#-------------------"
  },
  {
    "path": "mac-cli/tools/install",
    "chars": 3862,
    "preview": "#!/bin/sh\n\n# Colors\nGREEN='\\033[0;32m'\nLIGHTGREEN='\\033[1;32m'\nNC='\\033[1;37m'\nLIGHTBLUE='\\033[01;34m'\nNC='\\033[0m' # No"
  },
  {
    "path": "mac-cli/tools/uninstall",
    "chars": 210,
    "preview": "#!/bin/sh\n\nGREEN='\\033[0;32m'\nNC='\\033[0m' # No Color\n\nmain() {\n  echo \"Uninstalling Mac CLI...\"\n\trm /usr/local/bin/mac\n"
  },
  {
    "path": "mac-cli/tools/update",
    "chars": 500,
    "preview": "#!/bin/sh\n\nGREEN='\\033[0;32m'\nNC='\\033[0m' # No Color\n\nmain() {\n  echo \"Upgrading Mac CLI...\"\n\trm /usr/local/bin/mac\n\trm"
  }
]

About this extraction

This page contains the full source code of the guarinogabriel/Mac-CLI GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 20 files (58.4 KB), approximately 15.1k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!