├── LICENSE ├── install.sh ├── term.sh └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Habib Rehman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) 2016 Habib Rehman (https://git.io/HR) 3 | # Under MIT license 4 | # term installation file 5 | 6 | { # this ensures the entire script is downloaded # 7 | 8 | # From NVM install.sh 9 | detect_profile() { 10 | if [ -n "${PROFILE}" ] && [ -f "${PROFILE}" ]; then 11 | echo "${PROFILE}" 12 | return 13 | fi 14 | 15 | local DETECTED_PROFILE 16 | DETECTED_PROFILE='' 17 | local SHELLTYPE 18 | SHELLTYPE="$(basename "/$SHELL")" 19 | 20 | if [ "$SHELLTYPE" = "bash" ]; then 21 | if [ -f "$HOME/.bashrc" ]; then 22 | DETECTED_PROFILE="$HOME/.bashrc" 23 | elif [ -f "$HOME/.bash_profile" ]; then 24 | DETECTED_PROFILE="$HOME/.bash_profile" 25 | fi 26 | elif [ "$SHELLTYPE" = "zsh" ]; then 27 | DETECTED_PROFILE="$HOME/.zshrc" 28 | fi 29 | 30 | if [ -z "$DETECTED_PROFILE" ]; then 31 | if [ -f "$HOME/.profile" ]; then 32 | DETECTED_PROFILE="$HOME/.profile" 33 | elif [ -f "$HOME/.bashrc" ]; then 34 | DETECTED_PROFILE="$HOME/.bashrc" 35 | elif [ -f "$HOME/.bash_profile" ]; then 36 | DETECTED_PROFILE="$HOME/.bash_profile" 37 | elif [ -f "$HOME/.zshrc" ]; then 38 | DETECTED_PROFILE="$HOME/.zshrc" 39 | fi 40 | fi 41 | 42 | if [ ! -z "$DETECTED_PROFILE" ]; then 43 | echo "$DETECTED_PROFILE" 44 | fi 45 | } 46 | 47 | install_term_release () { 48 | local VERSION 49 | local RELEASE 50 | local RELEASE_URL 51 | local PROFILE 52 | VERSION=1.0 53 | RELEASE="v$VERSION.zip" 54 | RELEASE_URL="https://github.com/HR/term/archive/$RELEASE" 55 | PROFILE="$(detect_profile)" 56 | 57 | echo "Fetching term v$VERSION from $RELEASE_URL" 58 | 59 | # Make temporary dir 60 | mkdir /tmp/term 61 | cd /tmp/term 62 | # Fetch latest release 63 | curl -O $RELEASE_URL 64 | # Unzip 65 | unzip $RELEASE 66 | # Move term to home directory 67 | mv term.sh $HOME 68 | 69 | # Make term command globally available 70 | echo "source $HOME/term.sh" >> $PROFILE 71 | # Source default zsh rc 72 | source $PROFILE > /dev/null 73 | 74 | # delete tmp files 75 | cd .. 76 | rm -r term 77 | } 78 | 79 | install_term () { 80 | local RELEASE 81 | local PROFILE 82 | local INSTALL_PATH 83 | local SCRIPT_PATH 84 | local SOURCE_CMD 85 | RELEASE="https://raw.githubusercontent.com/HR/term/master/term.sh" 86 | PROFILE="$(detect_profile)" 87 | INSTALL_PATH="$HOME/.term" 88 | SCRIPT_PATH="$INSTALL_PATH/term.sh" 89 | SOURCE_CMD="source $SCRIPT_PATH > /dev/null" 90 | 91 | echo "" 92 | echo "" 93 | echo "Fetching term from $RELEASE" 94 | echo "" 95 | 96 | # Move term to home directory 97 | mkdir $INSTALL_PATH 98 | cd $INSTALL_PATH 99 | # Fetch latest release 100 | curl -O $RELEASE 101 | 102 | echo "" 103 | echo "Detected profile $PROFILE. Adding to it and sourcing..." 104 | echo "" 105 | # Make term command globally available 106 | command printf "${SOURCE_CMD}" >> "$PROFILE" 107 | # Source term.sh so it is immediately available 108 | # shellcheck source=/dev/null 109 | \. "${SCRIPT_PATH}" 110 | 111 | echo "" 112 | if [ $? -eq 0 ] 113 | then 114 | echo "Done! Successfully installed term ✅" 115 | else 116 | echo "Could not fully install term ❌" 117 | echo "Please report issue at https://git.io/term" 118 | fi 119 | 120 | } 121 | 122 | 123 | # Install term 124 | install_term 125 | 126 | } # this ensures the entire script is downloaded # -------------------------------------------------------------------------------- /term.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2016 Habib Rehman (https://git.io/HR) 3 | # Under MIT license 4 | # A (macOS) Terminal helper utility 5 | 6 | detect_profile() { 7 | if [ -n "${PROFILE}" ] && [ -f "${PROFILE}" ]; then 8 | echo "${PROFILE}" 9 | return 10 | fi 11 | 12 | local DETECTED_PROFILE 13 | DETECTED_PROFILE='' 14 | local SHELLTYPE 15 | SHELLTYPE="$(basename "/$SHELL")" 16 | 17 | if [ "$SHELLTYPE" = "bash" ]; then 18 | if [ -f "$HOME/.bashrc" ]; then 19 | DETECTED_PROFILE="$HOME/.bashrc" 20 | elif [ -f "$HOME/.bash_profile" ]; then 21 | DETECTED_PROFILE="$HOME/.bash_profile" 22 | fi 23 | elif [ "$SHELLTYPE" = "zsh" ]; then 24 | DETECTED_PROFILE="$HOME/.zshrc" 25 | fi 26 | 27 | if [ -z "$DETECTED_PROFILE" ]; then 28 | if [ -f "$HOME/.profile" ]; then 29 | DETECTED_PROFILE="$HOME/.profile" 30 | elif [ -f "$HOME/.bashrc" ]; then 31 | DETECTED_PROFILE="$HOME/.bashrc" 32 | elif [ -f "$HOME/.bash_profile" ]; then 33 | DETECTED_PROFILE="$HOME/.bash_profile" 34 | elif [ -f "$HOME/.zshrc" ]; then 35 | DETECTED_PROFILE="$HOME/.zshrc" 36 | fi 37 | fi 38 | 39 | if [ ! -z "$DETECTED_PROFILE" ]; then 40 | echo "$DETECTED_PROFILE" 41 | fi 42 | } 43 | 44 | term () { 45 | local PROFILE 46 | local VERSION 47 | VERSION=1.0 48 | PROFILE="$(detect_profile)" 49 | 50 | # If no args passed 51 | if [ -z "$1" ] 52 | then 53 | # new term at current dir 54 | open -a Terminal . 55 | return 0 56 | fi 57 | 58 | # If single arg passed 59 | if [ $# == 1 ] 60 | then 61 | case $1 in 62 | -s|--source) 63 | # Source the detected profile 64 | source $PROFILE > /dev/null 65 | return 0 66 | ;; 67 | -r|--repo) 68 | # Open git repo URL 69 | open "https://github.com/HR/term" 70 | return 0 71 | ;; 72 | -v|--version) 73 | # Check if running zsh 74 | echo "\nterm v$VERSION" 75 | echo "https://git.io/term\n" 76 | echo "Copyright (c) Habib Rehman (https://git.io/HR)" 77 | echo "Provided under the MIT License (MIT)" 78 | return 0 79 | ;; 80 | -h|--help) 81 | echo "" 82 | echo "term v$VERSION -- a Terminal helper utility\n" 83 | echo "usage:" 84 | echo " term [-h | --help] [-s script | --source script] [-e command | --exec command] [dir...]\n" 85 | echo "description:" 86 | echo " The term utility provides some very useful functionality. It can execute a 87 | command in a new Terminal window at the current directory or a specified 88 | directory. With no arguments specified, it opens a new Terminal window at the 89 | current directory. If multiple directories are specified then it opens each in a 90 | new Terminal window.\n" 91 | echo "options:" 92 | echo " -h show this help text" 93 | echo " -v show installed version" 94 | echo " -r open the term GitHub repo to report issue, star, provide feedback..." 95 | echo " -s source ~/.bash_profile or ~/.zshrc (auto detected)" 96 | echo " -s [script] source [script]" 97 | echo " -e [command] execute [command] in new window at current directory" 98 | echo " -e [command] [dir] execute [command] in new window at [dir] directory\n" 99 | echo "examples:\n" 100 | echo " term\n" 101 | echo " will open a new Terminal window at current directory\n" 102 | echo " term ~/Documents\n" 103 | echo " will open a new Terminal window at ~/Documents directory\n" 104 | echo " term ~/Documents ~/Pictures ~/Downloads/\n" 105 | echo " will open new Terminal windows at ~/Documents ~/Pictures ~/Downloads/ directories\n" 106 | echo " term -e echo hi\n" 107 | echo " will open a new Terminal window at current directory and execute \"echo hi\"\n" 108 | echo " term ~/Desktop -e \"echo hi && echo bye\"\n" 109 | echo " will open a new Terminal window at ~/Desktop directory and execute \"echo hi\" followed by \"echo bye\"\n" 110 | echo "For more please see https://git.io/term\n" 111 | return 0 112 | ;; 113 | *) 114 | # final fall back; just open the dirs 115 | open -a Terminal "$1" 116 | return 0 117 | ;; 118 | esac 119 | fi 120 | 121 | # If two or more args passed 122 | if [ $# -ge 2 ] 123 | then 124 | case $1 in 125 | -s*|--source*) 126 | source "${@:2}"; 127 | return 0 128 | ;; 129 | -e*|--exec*) 130 | # Execute the passed in command in new window at current dir 131 | cmd="cd $(pwd) && ${@:2}" # Command is from arg 2 onwards 132 | osascript -e 'tell application "Terminal" to do script with command "'"${cmd}"'"'; 133 | return 0 134 | ;; 135 | 136 | *) 137 | # now check second arg 138 | case $2 in 139 | -e*|--exec*) 140 | # Execute the passed in command in new window at the passed in dir 141 | cmd="cd $1 && ${@:3}" 142 | osascript -e 'tell application "Terminal" to do script with command "'"${cmd}"'"'; 143 | return 0 144 | ;; 145 | 146 | *) 147 | # final fall back; just open the dirs 148 | for dir in "$@" 149 | do 150 | open -a Terminal "$dir" 151 | done 152 | return 0 153 | ;; 154 | esac 155 | ;; 156 | esac 157 | fi 158 | } 159 | 160 | export -f term > /dev/null 161 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # term 2 | The term is a Terminal helper utility that provides some very useful 3 | functionality. It can execute a command in a new Terminal window at the current 4 | directory or a specified directory. With no arguments specified, it opens a new 5 | Terminal window at the current directory. If multiple directories are specified 6 | then it opens each in a new Terminal window. 7 | 8 | This may become a brew recipe at some point in the future. 9 | 10 | # Installation 11 | To install or update term, you can use the 12 | [install](https://raw.githubusercontent.com/HR/term/master/install.sh) script 13 | using cURL: 14 | ```shell 15 | $ curl -o- https://raw.githubusercontent.com/HR/term/master/install.sh | bash 16 | ``` 17 | or Wget: 18 | ```shell 19 | $ wget -qO- https://raw.githubusercontent.com/HR/term/master/install.sh | bash 20 | ``` 21 | The script clones the term repository to ~/.term and adds the source line to 22 | your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc). 23 | 24 | ## Manual installation 25 | First clone the repo 26 | ```shell 27 | $ git clone https://github.com/HR/term.git 28 | ``` 29 | Then set up a symlink of 'term' for the script by either sourcing it in your 30 | .bash_profile 31 | ```shell 32 | $ echo "source ~/GitHub/term/term.sh > /dev/null" >> ~/.bash_profile 33 | ``` 34 | or if you use zsh 35 | ```shell 36 | $ echo "source ~/GitHub/term/term.sh > /dev/null" >> ~/.zshrc 37 | ``` 38 | or add it to /usr/bin 39 | ```shell 40 | $ mv ~/GitHub/term/term.sh /usr/bin 41 | $ source ~/.bash_profile # to start using term immediately 42 | ``` 43 | 44 | # Usage 45 | To open a new shell at the current path 46 | ```shell 47 | $ term 48 | ``` 49 | 50 | To open a specific directory 51 | ```shell 52 | $ term [path to dir] 53 | ``` 54 | 55 | To open a multiple specific directories 56 | ```shell 57 | $ term [dir1 path] [dir2 path] [dir3 path] ... [dirN path] 58 | ``` 59 | These will all open in separate new Terminals. 60 | 61 | To source ~/.bash_profile or ~/.zshrc (term auto detect what you are using) 62 | ```shell 63 | $ term -s 64 | ``` 65 | 66 | To source a specified script 67 | ```shell 68 | $ term -s [script] 69 | ``` 70 | 71 | To execute a specified command in a new Terminal at current directory. 72 | ```shell 73 | $ term -e [command] 74 | ``` 75 | To get some help 76 | ```shell 77 | $ term -h 78 | > term v1.0.0 -- a Terminal helper utility 79 | > 80 | > usage: 81 | > term [-h | --help] [-s script | --source script] [-e command | --exec command] [dir...] 82 | > 83 | > description: 84 | > The term utility provides some very useful functionality. It can execute a 85 | > command in a new Terminal window at the current directory or a specified 86 | > directory. With no arguments specified, it opens a new Terminal window at the 87 | > current directory. If multiple directories are specified then it opens each in a 88 | > new Terminal window. 89 | > 90 | > options: 91 | > -h show this help text 92 | > -v show installed version 93 | > -r open the term GitHub repo to report issue, star, provide feedback... 94 | > -s source ~/.bash_profile or ~/.zshrc (auto detected) 95 | > -s [script] source [script] 96 | > -e [command] execute [command] in new window at current directory 97 | > -e [command] [dir] execute [command] in new window at [dir] directory 98 | > 99 | > examples: 100 | > 101 | > term 102 | > 103 | > will open a new Terminal window at current directory 104 | > 105 | > term ~/Documents 106 | > 107 | > will open a new Terminal window at ~/Documents directory 108 | > 109 | > term ~/Documents ~/Pictures ~/Downloads/ 110 | > 111 | > will open new Terminal windows at ~/Documents ~/Pictures ~/Downloads/ directories 112 | > 113 | > term -e echo hi 114 | > 115 | > will open a new Terminal window at current directory and execute "echo hi" 116 | > 117 | > term ~/Desktop -e "echo hi && echo bye" 118 | > 119 | > will open a new Terminal window at ~/Desktop directory and execute "echo hi" followed by "echo bye" 120 | ``` 121 | 122 | # Examples 123 | Some examples of using term 124 | 125 | ```shell 126 | $ term 127 | ``` 128 | This will open a new Terminal window at current directory 129 | 130 | ```shell 131 | $ term ~/Documents 132 | ``` 133 | This will open a new Terminal window at ~/Documents directory 134 | 135 | ```shell 136 | $ term ~/Documents ~/Pictures ~/Downloads/ 137 | ``` 138 | This will open new Terminal windows at ~/Documents ~/Pictures ~/Downloads/ directories 139 | 140 | ```shell 141 | $ term -e echo hi 142 | ``` 143 | This will open a new Terminal window at current directory and execute "echo hi" 144 | 145 | ```shell 146 | $ term ~/Desktop -e "echo hi && echo bye" 147 | ``` 148 | This will open a new Terminal window at ~/Desktop directory and execute "echo hi" followed by "echo hi" 149 | 150 | 151 | # Contributing 152 | Feel free to suggest any features and send in pull requests :) 153 | 154 | # License 155 | The MIT License (MIT) 156 | 157 | Copyright (c) Habib Rehman (https://git.io/HR) 158 | 159 | Permission is hereby granted, free of charge, to any person obtaining a copy 160 | of this software and associated documentation files (the "Software"), to deal 161 | in the Software without restriction, including without limitation the rights 162 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 163 | copies of the Software, and to permit persons to whom the Software is 164 | furnished todo so, subject to the following conditions: 165 | 166 | The above copyright notice and this permission notice shall be included in 167 | all copies or substantial portions of the Software. 168 | 169 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 170 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 171 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 172 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 173 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 174 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 175 | THE SOFTWARE. 176 | --------------------------------------------------------------------------------