Skip to content

Commit

Permalink
Merge pull request #42 from lukeberry99/add-command-line-editor-switch
Browse files Browse the repository at this point in the history
Open terminal editors last
  • Loading branch information
mattstauffer authored Aug 23, 2017
2 parents 077daae + 8bcefbc commit 49a31ea
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions lambo
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ green=$(tput setaf 2)
orange=$(tput setaf 3)
reset=$(tput sgr0)

## Terminal Editors
TERMINAL_EDITORS=("vim" "vi" "nano" "pico" "ed" "emacs" "nvim")

## Init functions
showhelp()
{
Expand Down Expand Up @@ -37,13 +40,18 @@ showhelp()
quit
}

isterminaleditor () {
for EDITOR in $TERMINAL_EDITORS; do [[ "$EDITOR" == "$CODEEDITOR" ]] && return 0; done
return 1
}

editconfig()
{
if [[ ! -f ~/.lambo/config ]]; then
echo "Config does not exist; creating."

makeconfig
return
return
fi

edit ~/.lambo/config
Expand Down Expand Up @@ -109,7 +117,7 @@ makeafter()
# To add a git commit after given modifications
# echo "Committing after modifications to Git"
# git add .
# git add .
# git commit -am "Initialize Composer dependencies and additional files."
' > ~/.lambo/after

Expand All @@ -118,13 +126,13 @@ makeafter()

edit()
{
## Open with best editor
## Open with best editor
if [[ $CODEEDITOR ]]; then
$CODEEDITOR $1
$CODEEDITOR $1
elif [[ $EDITOR ]]; then
$EDITOR $1
$EDITOR $1
else
vim $1
vim $1
fi
}

Expand All @@ -145,6 +153,8 @@ quit()
exit 0
}



## Set up error handling
trap 'abort' 0

Expand Down Expand Up @@ -274,7 +284,9 @@ fi
cd "$PROJECTNAME" || exit

if [[ "$CODEEDITOR" != "" ]]; then
$CODEEDITOR .
if ! isterminaleditor; then
$CODEEDITOR .
fi
fi

if [[ "$NODE" = true ]]; then
Expand Down Expand Up @@ -335,6 +347,12 @@ if [[ -f ~/.lambo/after ]]; then
source ~/.lambo/after
fi

if [[ "$CODEEDITOR" != "" ]]; then
if isterminaleditor; then
$CODEEDITOR .
fi
fi

if [[ "$SHELL" != "" ]]; then
exec "$SHELL"

Expand All @@ -351,5 +369,7 @@ else
You're ready to go! Remember to cd into '${green}$prettyPath${reset}' before you start editing."
fi



# End script; disable error handling
trap : 0

0 comments on commit 49a31ea

Please sign in to comment.