mirror of
https://github.com/iridakos/goto.git
synced 2025-05-16 07:20:17 -07:00
Merge remote-tracking branch 'upstream/master' into feature/expand_command
This commit is contained in:
commit
1c397b1700
22
README.md
22
README.md
@ -1,6 +1,6 @@
|
|||||||
# goto
|
# goto
|
||||||
|
|
||||||
`goto` is a bash utility allowing users to change faster to aliased directories supporting auto-completion :feet:
|
`goto` is a shell utility allowing users to change faster to aliased directories supporting auto-completion :feet:
|
||||||
|
|
||||||
## How does it work?
|
## How does it work?
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ goto dev
|
|||||||
|
|
||||||
## goto completion
|
## goto completion
|
||||||
|
|
||||||
`goto` comes with a nice auto-completion script so that whenever you press the `tab` key after the `goto` command, bash prompts with suggestions of the available aliases:
|
`goto` comes with a nice auto-completion script so that whenever you press the `tab` key after the `goto` command, bash or zsh prompts with suggestions of the available aliases:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ goto <tab>
|
$ goto <tab>
|
||||||
@ -28,12 +28,21 @@ rubies /home/iridakos/.rvm/rubies
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Copy the file `goto.bash` somewhere in your filesystem and add a line in your `.bashrc` to source it.
|
### Via script
|
||||||
|
Clone the repository and run the install script as super user or root:
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/iridakos/goto.git
|
||||||
|
cd goto
|
||||||
|
sudo ./install
|
||||||
|
```
|
||||||
|
|
||||||
For example, if you placed the file in your home folder, all you have to do is add the following line to your `.bashrc` file:
|
### Manually
|
||||||
|
Copy the file `goto.sh` somewhere in your filesystem and add a line in your `.zshrc` or `.bashrc` to source it.
|
||||||
|
|
||||||
|
For example, if you placed the file in your home folder, all you have to do is add the following line to your `.zshrc` or `.bashrc` file:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
source ~/goto.bash
|
source ~/goto.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@ -75,7 +84,7 @@ goto --register blog /mnt/external/projects/html/blog
|
|||||||
goto -r last_release .
|
goto -r last_release .
|
||||||
```
|
```
|
||||||
and it will automatically be aliased to the whole path.
|
and it will automatically be aliased to the whole path.
|
||||||
* Pressing the `tab` key after the alias name, you have the default directory suggestions by bash.
|
* Pressing the `tab` key after the alias name, you have the default directory suggestions by the shell.
|
||||||
|
|
||||||
### Unregister an alias
|
### Unregister an alias
|
||||||
|
|
||||||
@ -168,7 +177,6 @@ goto --version
|
|||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
* ~~Test on macOS~~ extensively
|
* ~~Test on macOS~~ extensively
|
||||||
* Fix `zsh` issues [[#7](https://github.com/iridakos/goto/issues/7), ...]
|
|
||||||
* Write [tests](https://github.com/iridakos/goto/issues/2)
|
* Write [tests](https://github.com/iridakos/goto/issues/2)
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env sh
|
||||||
|
# shellcheck disable=SC2039
|
||||||
# MIT License
|
# MIT License
|
||||||
#
|
#
|
||||||
# Copyright (c) 2018 Lazarus Lazaridis
|
# Copyright (c) 2018 Lazarus Lazaridis
|
||||||
@ -23,9 +24,10 @@
|
|||||||
|
|
||||||
# Changes to the given alias directory
|
# Changes to the given alias directory
|
||||||
# or executes a command based on the arguments.
|
# or executes a command based on the arguments.
|
||||||
function goto()
|
goto()
|
||||||
{
|
{
|
||||||
local target
|
local target
|
||||||
|
_goto_resolve_db
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
# display usage and exit when no args
|
# display usage and exit when no args
|
||||||
@ -61,9 +63,15 @@ function goto()
|
|||||||
_goto_directory "$subcommand"
|
_goto_directory "$subcommand"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
function _goto_usage()
|
_goto_resolve_db()
|
||||||
|
{
|
||||||
|
GOTO_DB="$HOME/.goto"
|
||||||
|
}
|
||||||
|
|
||||||
|
_goto_usage()
|
||||||
{
|
{
|
||||||
cat <<\USAGE
|
cat <<\USAGE
|
||||||
usage: goto [<option>] <alias> [<directory>]
|
usage: goto [<option>] <alias> [<directory>]
|
||||||
@ -90,38 +98,40 @@ USAGE
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Displays version
|
# Displays version
|
||||||
function _goto_version()
|
_goto_version()
|
||||||
{
|
{
|
||||||
echo "goto version 1.0.0"
|
echo "goto version 1.0.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Expands directory.
|
# Expands directory.
|
||||||
# Helpful for ~, ., .. paths
|
# Helpful for ~, ., .. paths
|
||||||
function _goto_expand_directory()
|
_goto_expand_directory()
|
||||||
{
|
{
|
||||||
cd "$1" 2>/dev/null && pwd
|
cd "$1" 2>/dev/null && pwd
|
||||||
}
|
}
|
||||||
|
|
||||||
# Lists registered aliases.
|
# Lists registered aliases.
|
||||||
function _goto_list_aliases()
|
_goto_list_aliases()
|
||||||
{
|
{
|
||||||
local IFS=$'\n'
|
local IFS=$'\n'
|
||||||
if [ -f ~/.goto ]; then
|
if [ -f "$GOTO_DB" ]; then
|
||||||
sed '/^\s*$/d' ~/.goto 2>/dev/null
|
sed '/^\s*$/d' "$GOTO_DB" 2>/dev/null
|
||||||
else
|
else
|
||||||
echo "You haven't configured any directory aliases yet."
|
echo "You haven't configured any directory aliases yet."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Expands a registered alias.
|
# Expands a registered alias.
|
||||||
function _goto_expand_alias()
|
_goto_expand_alias()
|
||||||
{
|
{
|
||||||
if [ "$#" -ne "1" ]; then
|
if [ "$#" -ne "1" ]; then
|
||||||
_goto_error "usage: goto -x|--expand <alias>"
|
_goto_error "usage: goto -x|--expand <alias>"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local resolved=$(_goto_find_alias_directory $1)
|
local resolved
|
||||||
|
|
||||||
|
resolved=$(_goto_find_alias_directory "$1")
|
||||||
if [ -z "$resolved" ]; then
|
if [ -z "$resolved" ]; then
|
||||||
_goto_error "alias '$1' does not exist"
|
_goto_error "alias '$1' does not exist"
|
||||||
return
|
return
|
||||||
@ -130,17 +140,26 @@ function _goto_expand_alias()
|
|||||||
echo "$resolved"
|
echo "$resolved"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Registers an alias.
|
# Lists duplicate directory aliases
|
||||||
function _goto_register_alias()
|
_goto_find_duplicate()
|
||||||
|
{
|
||||||
|
local duplicates=
|
||||||
|
|
||||||
|
duplicates=$(sed -n 's:[^ ]* '"$1"'$:&:p' "$GOTO_DB" 2>/dev/null)
|
||||||
|
echo "$duplicates"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Registers and alias.
|
||||||
|
_goto_register_alias()
|
||||||
{
|
{
|
||||||
if [ "$#" -ne "2" ]; then
|
if [ "$#" -ne "2" ]; then
|
||||||
_goto_error "usage: goto -r|--register <alias> <directory>"
|
_goto_error "usage: goto -r|--register <alias> <directory>"
|
||||||
return
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [[ $1 =~ ^[[:alnum:]]+[a-zA-Z0-9_-]*$ ]]; then
|
if ! [[ $1 =~ ^[[:alnum:]]+[a-zA-Z0-9_-]*$ ]]; then
|
||||||
_goto_error "invalid alias - can start with letters or digits followed by letters, digits, hyphens or underscores"
|
_goto_error "invalid alias - can start with letters or digits followed by letters, digits, hyphens or underscores"
|
||||||
return
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local resolved
|
local resolved
|
||||||
@ -148,96 +167,111 @@ function _goto_register_alias()
|
|||||||
|
|
||||||
if [ -n "$resolved" ]; then
|
if [ -n "$resolved" ]; then
|
||||||
_goto_error "alias '$1' exists"
|
_goto_error "alias '$1' exists"
|
||||||
return
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local directory
|
local directory
|
||||||
directory=$(_goto_expand_directory "$2")
|
directory=$(_goto_expand_directory "$2")
|
||||||
if [ -z "$directory" ]; then
|
if [ -z "$directory" ]; then
|
||||||
_goto_error "failed to register '$1' to '$2' - can't cd to directory"
|
_goto_error "failed to register '$1' to '$2' - can't cd to directory"
|
||||||
return
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local duplicate
|
||||||
|
duplicate=$(_goto_find_duplicate "$directory")
|
||||||
|
if [ -n "$duplicate" ]; then
|
||||||
|
_goto_warning "duplicate alias(es) found: \\n$duplicate"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Append entry to file.
|
# Append entry to file.
|
||||||
echo "$1 $directory" >> ~/.goto
|
echo "$1 $directory" >> "$GOTO_DB"
|
||||||
echo "Alias '$1' registered successfully."
|
echo "Alias '$1' registered successfully."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Unregisters the given alias.
|
# Unregisters the given alias.
|
||||||
function _goto_unregister_alias
|
_goto_unregister_alias()
|
||||||
{
|
{
|
||||||
if [ "$#" -ne "1" ]; then
|
if [ "$#" -ne "1" ]; then
|
||||||
_goto_error "usage: goto -u|--unregister <alias>"
|
_goto_error "usage: goto -u|--unregister <alias>"
|
||||||
return
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local resolved
|
local resolved
|
||||||
resolved=$(_goto_find_alias_directory "$1")
|
resolved=$(_goto_find_alias_directory "$1")
|
||||||
if [ -z "$resolved" ]; then
|
if [ -z "$resolved" ]; then
|
||||||
_goto_error "alias '$1' does not exist"
|
_goto_error "alias '$1' does not exist"
|
||||||
return
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
local readonly GOTO_DB_TMP="$HOME/.goto_"
|
||||||
# Delete entry from file.
|
# Delete entry from file.
|
||||||
sed "/^$1 /d" ~/.goto > ~/.goto_ && mv ~/.goto_ ~/.goto
|
sed "/^$1 /d" "$GOTO_DB" > "$GOTO_DB_TMP" && mv "$GOTO_DB_TMP" "$GOTO_DB"
|
||||||
echo "Alias '$1' unregistered successfully."
|
echo "Alias '$1' unregistered successfully."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Unregisters aliases whose directories no longer exist.
|
# Unregisters aliases whose directories no longer exist.
|
||||||
function _goto_cleanup()
|
_goto_cleanup()
|
||||||
{
|
{
|
||||||
if ! [ -f ~/.goto ]; then
|
if ! [ -f "$GOTO_DB" ]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local IFS=$'\n' match matches al dir
|
while IFS= read -r i && [ -n "$i" ]; do
|
||||||
|
echo "Cleaning up: $i"
|
||||||
read -d '' -r -a matches < ~/.goto
|
_goto_unregister_alias "$i"
|
||||||
|
done <<< "$(awk '{al=$1; $1=""; dir=substr($0,2);
|
||||||
IFS=' '
|
system("[ ! -d \"" dir "\" ] && echo " al)}' "$GOTO_DB")"
|
||||||
for i in "${!matches[@]}"; do
|
|
||||||
read -r -a match <<< "${matches[$i]}"
|
|
||||||
|
|
||||||
al="${match[0]}"
|
|
||||||
dir="${match[*]:1}"
|
|
||||||
|
|
||||||
if [ -n "$al" ] && [ ! -d "$dir" ]; then
|
|
||||||
echo "Cleaning up: $al - $dir"
|
|
||||||
_goto_unregister_alias "$al"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Changes to the given alias' directory
|
# Changes to the given alias' directory
|
||||||
function _goto_directory()
|
_goto_directory()
|
||||||
{
|
{
|
||||||
local target
|
local target
|
||||||
|
|
||||||
target=$(_goto_resolve_alias "$1")
|
target=$(_goto_resolve_alias "$1") || return 1
|
||||||
|
|
||||||
if [ -n "$target" ]; then
|
cd "$target" 2> /dev/null || \
|
||||||
cd "$target" || _goto_error "Failed to goto '$target'"
|
{ _goto_error "Failed to goto '$target'" && return 1; }
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Fetches the alias directory.
|
# Fetches the alias directory.
|
||||||
function _goto_find_alias_directory()
|
_goto_find_alias_directory()
|
||||||
{
|
{
|
||||||
local resolved
|
local resolved
|
||||||
|
|
||||||
resolved=$(sed -n "s/^$1 \\(.*\\)/\\1/p" ~/.goto 2>/dev/null)
|
resolved=$(sed -n "s/^$1 \\(.*\\)/\\1/p" "$GOTO_DB" 2>/dev/null)
|
||||||
echo "$resolved"
|
echo "$resolved"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Displays the given error.
|
# Displays the given error.
|
||||||
# Used for common error output.
|
# Used for common error output.
|
||||||
function _goto_error()
|
_goto_error()
|
||||||
{
|
{
|
||||||
(>&2 echo "goto error: $1")
|
(>&2 echo -e "goto error: $1")
|
||||||
|
}
|
||||||
|
|
||||||
|
# Displays the given warning.
|
||||||
|
# Used for common warning output.
|
||||||
|
_goto_warning()
|
||||||
|
{
|
||||||
|
(>&2 echo -e "goto warning: $1")
|
||||||
|
}
|
||||||
|
|
||||||
|
# Displays entries with aliases starting as the given one.
|
||||||
|
_goto_print_similar()
|
||||||
|
{
|
||||||
|
local similar
|
||||||
|
|
||||||
|
similar=$(sed -n "/^$1[^ ]* .*/p" "$GOTO_DB" 2>/dev/null)
|
||||||
|
if [ -n "$similar" ]; then
|
||||||
|
(>&2 echo "Did you mean:")
|
||||||
|
(>&2 echo "$similar" | column -t)
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Fetches alias directory, errors if it doesn't exist.
|
# Fetches alias directory, errors if it doesn't exist.
|
||||||
function _goto_resolve_alias()
|
_goto_resolve_alias()
|
||||||
{
|
{
|
||||||
local resolved
|
local resolved
|
||||||
|
|
||||||
@ -245,14 +279,15 @@ function _goto_resolve_alias()
|
|||||||
|
|
||||||
if [ -z "$resolved" ]; then
|
if [ -z "$resolved" ]; then
|
||||||
_goto_error "unregistered alias $1"
|
_goto_error "unregistered alias $1"
|
||||||
echo ""
|
_goto_print_similar "$1"
|
||||||
|
return 1
|
||||||
else
|
else
|
||||||
echo "${resolved}"
|
echo "${resolved}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Completes the goto function with the available commands
|
# Completes the goto function with the available commands
|
||||||
function _complete_goto_commands()
|
_complete_goto_commands()
|
||||||
{
|
{
|
||||||
local IFS=$' \t\n'
|
local IFS=$' \t\n'
|
||||||
|
|
||||||
@ -261,12 +296,13 @@ function _complete_goto_commands()
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Completes the goto function with the available aliases
|
# Completes the goto function with the available aliases
|
||||||
function _complete_goto_aliases()
|
_complete_goto_aliases()
|
||||||
{
|
{
|
||||||
local IFS=$'\n' matches al
|
local IFS=$'\n' matches
|
||||||
|
_goto_resolve_db
|
||||||
|
|
||||||
# shellcheck disable=SC2207
|
# shellcheck disable=SC2207
|
||||||
matches=($(sed -n "/^$1/p" ~/.goto 2>/dev/null))
|
matches=($(sed -n "/^$1/p" "$GOTO_DB" 2>/dev/null))
|
||||||
|
|
||||||
if [ "${#matches[@]}" -eq "1" ]; then
|
if [ "${#matches[@]}" -eq "1" ]; then
|
||||||
# remove the filenames attribute from the completion method
|
# remove the filenames attribute from the completion method
|
||||||
@ -291,7 +327,7 @@ function _complete_goto_aliases()
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Bash programmable completion for the goto function
|
# Bash programmable completion for the goto function
|
||||||
function _complete_goto()
|
_complete_goto_bash()
|
||||||
{
|
{
|
||||||
local cur="${COMP_WORDS[$COMP_CWORD]}" prev
|
local cur="${COMP_WORDS[$COMP_CWORD]}" prev
|
||||||
|
|
||||||
@ -329,9 +365,51 @@ function _complete_goto()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Register the goto compspec
|
# Zsh programmable completion for the goto function
|
||||||
if ! [[ $(uname -s) =~ Darwin* ]]; then
|
_complete_goto_zsh()
|
||||||
complete -o filenames -F _complete_goto goto
|
{
|
||||||
|
local all_aliases=()
|
||||||
|
while IFS= read -r line; do
|
||||||
|
all_aliases+=("$line")
|
||||||
|
done <<< "$(sed -e 's/ /:/g' ~/.goto 2>/dev/null)"
|
||||||
|
|
||||||
|
local state
|
||||||
|
local -a options=(
|
||||||
|
'(1)'{-r,--register}'[registers an alias]:register:->register'
|
||||||
|
'(- 1 2)'{-u,--unregister}'[unregisters an alias]:unregister:->unregister'
|
||||||
|
'(: -)'{-l,--list}'[lists aliases]'
|
||||||
|
'(*)'{-c,--cleanup}'[cleans up non existent directory aliases]'
|
||||||
|
'(: -)'{-h,--help}'[prints this help]'
|
||||||
|
'(* -)'{-v,--version}'[displays the version of the goto script]'
|
||||||
|
)
|
||||||
|
|
||||||
|
_arguments -C \
|
||||||
|
"${options[@]}" \
|
||||||
|
'1:alias:->aliases' \
|
||||||
|
'2:dir:_files' \
|
||||||
|
&& ret=0
|
||||||
|
|
||||||
|
case ${state} in
|
||||||
|
(aliases)
|
||||||
|
_describe -t aliases 'goto aliases:' all_aliases && ret=0
|
||||||
|
;;
|
||||||
|
(unregister)
|
||||||
|
_describe -t aliases 'unregister alias:' all_aliases && ret=0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
return $ret
|
||||||
|
}
|
||||||
|
|
||||||
|
# Register the goto completions.
|
||||||
|
if [ -n "${BASH_VERSION}" ]; then
|
||||||
|
if ! [[ $(uname -s) =~ Darwin* ]]; then
|
||||||
|
complete -o filenames -F _complete_goto_bash goto
|
||||||
|
else
|
||||||
|
complete -F _complete_goto_bash goto
|
||||||
|
fi
|
||||||
|
elif [ -n "${ZSH_VERSION}" ]; then
|
||||||
|
compdef _complete_goto_zsh goto
|
||||||
else
|
else
|
||||||
complete -F _complete_goto goto
|
echo "Unsupported shell."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
61
install
Executable file
61
install
Executable file
@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# MIT License
|
||||||
|
#
|
||||||
|
# Copyright (c) 2018 Lazarus Lazaridis
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
function _goto_install_error()
|
||||||
|
{
|
||||||
|
echo "$@" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
# sudo-check
|
||||||
|
if [ $EUID -ne 0 ]; then
|
||||||
|
_goto_install_error 'Please run this script in sudo mode or as root user'
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
GOTO_FILE_LOCATION='/usr/local/share/goto.sh'
|
||||||
|
RC=""
|
||||||
|
if [ -f ~/.bashrc ]; then
|
||||||
|
RC="$HOME/.bashrc"
|
||||||
|
elif [ -f ~/.cshrc ]; then
|
||||||
|
RC="$HOME/.cshrc"
|
||||||
|
elif [ -f ~/.kshrc ]; then
|
||||||
|
RC="$HOME/.kshrc"
|
||||||
|
elif [ -f ~/.zshrc ]; then
|
||||||
|
RC="$HOME/.zshrc"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cp ./goto.sh "$GOTO_FILE_LOCATION"
|
||||||
|
|
||||||
|
if [ -n "$RC" ]; then
|
||||||
|
# Append source to RC startup file if not already there
|
||||||
|
if [ "$(grep -c "source $GOTO_FILE_LOCATION" "$RC")" == "0" ]; then
|
||||||
|
# Append source to RC file
|
||||||
|
echo -e "\\n\\n# Source goto\\n[[ -s \"$GOTO_FILE_LOCATION\" ]] && source $GOTO_FILE_LOCATION\\n" >> "$RC"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
source "$GOTO_FILE_LOCATION"
|
||||||
|
else
|
||||||
|
_goto_install_error "Error sourcing goto in your startup file.."
|
||||||
|
_goto_install_error "E.g ~/.bashrc ~/.cshrc etc.."
|
||||||
|
fi
|
Loading…
x
Reference in New Issue
Block a user