Skip to content

Instantly share code, notes, and snippets.

@aaripurna
Last active June 9, 2019 10:17
Show Gist options
  • Save aaripurna/9a1dad154d3ebafa8eb5291c36cf7640 to your computer and use it in GitHub Desktop.
Save aaripurna/9a1dad154d3ebafa8eb5291c36cf7640 to your computer and use it in GitHub Desktop.
generate editor config for certain project
#!/bin/bash
set -e
export ror='https://gist.githubusercontent.com/aaripurna/56ff2ab5f6320984c105f337d500cd3f/raw'
get-config() {
link=${!1}
if [[ ! -z $link ]]; then
curl -L $link | tee $HOME/.editorconfig/$1
else
echo "Invalid arguments try editorconfig --help"
exit 1
fi
}
generate-config-remote() {
link=${!1}
if [[ ! -z $link ]]; then
curl -L $link | tee .editorconfig
else
echo "Invalid arguments try editorconfig --help"
exit 1
fi
}
generate-config-local() {
cat $HOME/.editorconfig/$1 | tee .editorconfig
}
generate() {
if [[ ! -d $HOME/.editorconfig ]]; then
if [[ -f $HOME/.editorconfig/$1 ]]; then
generate-config-local $1
else
generate-config-remote $1
fi
else
generate-config-remote $1
fi
}
save() {
if [[ ! -d $HOME/.editorconfig ]]; then
mkdir $HOME/.editorconfig
get-config $1
generate $1
else
get-config $1
generate $1
fi
}
get() {
if [[ ! -f $HOME/.editorconfig/$1 ]]; then
echo "$1 exist in directory"
else
get-config $1
fi
}
profile() {
if [[ "$SHELL" == "/usr/bin/zsh" ]]; then
echo $HOME/.zshrc
elif [[ "$SHELL" == "/bin/bash" ]]; then
if [[ -f $HOME/.bashrc ]]; then
echo $HOME/.bashrc
elif [[ -f $HOME/.bash_profile ]]; then
echo $HOME/.bash_profile
fi
fi
}
download() {
if [[ ! -d $HOME/.editorconfig ]]; then
mkdir $HOME/.editorconfig
fi
cd $HOME/.editorconfig
curl -o main -L https://gist.githubusercontent.com/aaripurna/9a1dad154d3ebafa8eb5291c36cf7640/raw
cat <<- "EOF" | tee -a $(profile)
editorconfig() {
bash $HOME/.editorconfig/main $@
}
EOF
}
if [[ "$1" == "--download" ]]; then
download
echo "Succed"
elif [[ $# -ge 2 ]]; then
if [[ "$1" == "add" ]]; then
save $2
echo "$1 editorconfig added to the your local library"
echo "$1 editorconfig added to the your project"
elif [[ "$1" == "generate" ]] || [[ $1 == "g" ]]; then
generate $2
echo "$1 editorconfig added to the your project"
fi
else
cat <<- "EOF"
failed!
invalid argument
EOF
exit 1
fi
@aaripurna
Copy link
Author

aaripurna commented Jun 2, 2019

only compatible with ruby on rails project for this moment

to download "

curl -L https://gist.githubusercontent.com/aaripurna/9a1dad154d3ebafa8eb5291c36cf7640/raw  | bash -s -- --download

reload terminal

editorconfig g ror #for ruby on rails

tested on ubuntu 18.04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment