feat: setup.sh

This commit is contained in:
max_richter 2020-11-07 15:58:15 +01:00
parent 747b24bc75
commit 0cb86839b2
15 changed files with 1709 additions and 318 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.gitconfig*

1578
.p10k.zsh

File diff suppressed because it is too large Load Diff

202
.zshrc
View File

@ -7,12 +7,8 @@ fi
ZSH_THEME="powerlevel10k/powerlevel10k"
## for vxcsrv on wsl
export GOPATH="/home/jim/Sync"
plugins=(
git
npm
zsh-autosuggestions
)
@ -23,198 +19,12 @@ export ZSH=~/.oh-my-zsh
source $ZSH/oh-my-zsh.sh
## FUNCTIONS ##
source $HOME/.dotfiles/zsh/functions.zsh
# Helps navigating Sync directory
function fx(){
cd /home/jim/Sync/
if [ "$1" = "o" ]; then
cd $2
code-insiders .
if [ "$3" = "live" ]; then
command live-server
fi
elif [ "$1" = "w" ]; then
cd /Library/WebServer/Documents/
elif [ "$1" = "s" ]; then
cd $2
fi
}
# Helps navigating wordpress directory
function wp(){
first_dir=${1%/*}
second_dir=${1#*/}
if [ $first_dir = $second_dir ]; then
second_dir=""
fi
if [ $first_dir = "plugins" ]; then
cd "wp-content/plugins"
elif [ $first_dir = "themes" ]; then
cd "wp-content/themes"
fi
if [ $second_dir != "" ]; then
fi
}
# Helps navigating COCO directory
function co(){
cd ~/COCO
openCode=false
if [ "$1" = "o" ]; then
1=$2;
openCode=true
fi
first_dir=${1%/*};
second_dir=${1#*/};
if [ -z $first_dir ]; then
first_dir=""
fi
if [ -z $second_dir ]; then
second_dir=""
fi
if [ ! -v $first_dir ]; then
coco_dir=$(ls | grep $first_dir | head -n 1)
if [ -z "$coco_dir" ]; then
echo "No directory exists for course $first_dir. Create a new one? (y/n)"
read createDir
if [ "$createDir" = "y" ]; then
echo "What should the name be?"
read dirName
dirName=$first_dir"_$dirName"
mkdir $dirName
cd $dirName
echo "Created $dirName"
fi
else
cd $coco_dir
amount=$(find ./* -maxdepth 0 -type d | wc -l)
if [ "$amount" = "1" ]; then
dir=$(find ./* -maxdepth 0 -type d)
cd $dir
fi
fi
if [ $second_dir != $first_dir ]; then
cd $second_dir
fi
fi
if [ $openCode = true ]; then
code-insiders .
fi
}
# Helps with starting stuff
function start(){
serviceName=$1;
if [ $serviceName = "docker" ]; then
dockerStatus="$(service docker status)"
if [ "${dockerStatus#*"not running"}" != "$dockerStatus" ]; then
echo "➜ starting docker"
echo "$(sudo service docker start)"
fi
sleep 0.5
elif [ $serviceName = "mongo" ]; then
start docker
start container mongo
elif [ $serviceName = "dc" ]; then
start docker
echo "➜ starting docker-compose"
dc up -d
elif [ $serviceName = "spring" ]; then
start mongo
echo "➜ starting spring-boot"
mvn spring-boot:run
elif [ $serviceName = "container" ]; then
containerName=$2;
containerInfo="[port:$(docker port $containerName) volume:$(docker inspect -f '{{index (.HostConfig.Binds) 0}}' $containerName)]"
containerIsRunning="$(docker inspect -f '{{.State.Running}}' $containerName 2>/dev/null)"
containerStatus="$(docker inspect -f '{{.State.Status}}' $containerName 2>/dev/null)"
if [ $containerIsRunning = "true" ]; then
echo "$containerName already running $containerInfo"
elif [ $containerStatus = "exited" ]; then
echo "➜ running $containerName $containerInfo"
echo "➜ id:$(sudo docker start $containerName)"
else
echo "➜ container $containerName $containerInfo doesnt exist"
fi
elif [ $serviceName = "dc" ]; then
start docker
echo "➜ starting docker-compose"
dc up -d
fi
}
## ALIASES ##
source $HOME/.dotfiles/zsh/aliases.sh
## LOADING PROGRAMS
export PATH="$PATH:/usr/local/sbin"
export PATH="$PATH:/opt/local/bin"
export PATH="$PATH:/usr/local"
@ -228,11 +38,11 @@ export PATH="$PATH:$HOME/go/bin"
eval "$(direnv hook zsh)"
#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="/home/jim/.sdkman"
[[ -s "/home/jim/.sdkman/bin/sdkman-init.sh" ]] && source "/home/jim/.sdkman/bin/sdkman-init.sh"
export SDKMAN_DIR="$HOME/.sdkman"
[[ -s "$HOME/jim/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# Go version manager
[[ -s "/home/jim/.gvm/scripts/gvm" ]] && source "/home/jim/.gvm/scripts/gvm"
[[ -s "/$HOME/.gvm/scripts/gvm" ]] && source "/$HOME/.gvm/scripts/gvm"

8
Dockerfile Normal file
View File

@ -0,0 +1,8 @@
FROM debian:latest
ADD . ~/.dotfiles
RUN apt-get update && apt-get upgrade -y
RUN apt-get install curl git -y
ENTRYPOINT ~/.dotfiles/setup.sh

View File

@ -1 +1,10 @@
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
#Install oh my zsh
export CHSH=no
export RUNZSH=no
export KEEP_ZSHRC=yes
echo " - installing oh-my-zsh"
sh -c "$(
curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
)" > /dev/null
echo " - finished"

View File

@ -1 +1,3 @@
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
echo " - cloning github.com/zsh-users/zsh-autosuggestions into ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k"
git clone --quiet --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k > /dev/null
echo " - finished"

View File

@ -0,0 +1,3 @@
echo " - cloning github.com/zsh-users/zsh-autosuggestions into ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions"
git clone --quiet https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions > /dev/null
echo " - finished"

View File

@ -1,4 +1,5 @@
#!/bin/bash
cd "$(dirname "$0")"
function isInstalled(){
if [ "$(which $1)" != "" ]; then
@ -27,22 +28,49 @@ function installOptional(){
function install {
# Check if program is already installed
if isInstalled $1; then
echo "$1 is already installed"
echo " - $1 is already installed"
else
echo "installing $1"
apt-get install $1
echo " - installing $1 ..."
apt-get install $1 -y > /dev/null
echo " - finished"
fi
}
function linkFile {
#Move old file
if [ -f "$HOME/$1" ]; then
echo " - moving old file to $1_bak"
mv "$HOME/$1" "$HOME/$1_bak"
fi
#Link $1
echo " - linking $(pwd)/$1 --> $HOME/$1"
ln -s "$(pwd)/$1" "$HOME/$1"
}
#Prerequesits
echo "-- Installing prerequisites --"
install git
install curl
echo "-- Linking .dotfiles --"
linkFile .bashrc
linkFile .zshrc
linkFile .p10k.zsh
linkFile .gitconfig
linkFile .dircolors
linkFile .gitconfig-coco
echo "-- Installing Oh-My-Zsh --"
install zsh
./install/oh-my-szh.sh
./install/p10k.sh
install nope
sh $(pwd)/install/oh-my-zsh.sh
sh $(pwd)/install/zsh-autosuggestions.sh
zsh $(pwd)/install/p10k.sh
install direnv
echo "-- Applying .zshrc --"
chsh -s $(which zsh)
export SHELL=$(which zsh)
zsh

View File

@ -6,8 +6,6 @@ alias yoink="curl"
alias pls='sudo -E env "PATH=$PATH"'
alias lc='colorls -lA --s'
alias zshc="vim ~/.zshrc"
alias zshu="source ~/.zshrc"
@ -15,11 +13,6 @@ alias nano="nvim"
alias ww="webpack -w"
alias ys="yarn start"
alias yd="yarn dev"
alias yi="yarn install"
alias ya="yarn add"
alias gs="git status"
alias gaa="git add ."
alias gpm="git push origin master"

View File

@ -1 +1,5 @@
source ./y.sh;
source $(dirname "$0")/functions/co.zsh;
source $(dirname "$0")/functions/fx.zsh;
source $(dirname "$0")/functions/start.zsh;
source $(dirname "$0")/functions/wp.zsh;
source $(dirname "$0")/functions/y.zsh;

65
zsh/functions/co.zsh Normal file
View File

@ -0,0 +1,65 @@
# Helps navigating COCO directory
function co(){
cd ~/COCO
openCode=false
if [ "$1" = "o" ]; then
1=$2;
openCode=true
fi
first_dir=${1%/*};
second_dir=${1#*/};
if [ -z $first_dir ]; then
first_dir=""
fi
if [ -z $second_dir ]; then
second_dir=""
fi
if [ ! -v $first_dir ]; then
coco_dir=$(ls | grep $first_dir | head -n 1)
if [ -z "$coco_dir" ]; then
echo "No directory exists for course $first_dir. Create a new one? (y/n)"
read createDir
if [ "$createDir" = "y" ]; then
echo "What should the name be?"
read dirName
dirName=$first_dir"_$dirName"
mkdir $dirName
cd $dirName
echo "Created $dirName"
fi
else
cd $coco_dir
amount=$(find ./* -maxdepth 0 -type d | wc -l)
if [ "$amount" = "1" ]; then
dir=$(find ./* -maxdepth 0 -type d)
cd $dir
fi
fi
if [ $second_dir != $first_dir ]; then
cd $second_dir
fi
fi
if [ $openCode = true ]; then
code-insiders .
fi
}

12
zsh/functions/fx.zsh Normal file
View File

@ -0,0 +1,12 @@
# Helps navigating Sync directory
function fx(){
cd $HOME/SYNC/
if [ "$2" != "" ]; then
cd $2
fi
if [ "$1" = "o" ]; then
code-insiders .
fi
}

68
zsh/functions/start.zsh Normal file
View File

@ -0,0 +1,68 @@
# Helps with starting stuff
function start(){
serviceName=$1;
if [ $serviceName = "docker" ]; then
dockerStatus="$(service docker status)"
if [ "${dockerStatus#*"not running"}" != "$dockerStatus" ]; then
echo "➜ starting docker"
echo "$(sudo service docker start)"
fi
sleep 0.5
elif [ $serviceName = "mongo" ]; then
start docker
start container mongo
elif [ $serviceName = "dc" ]; then
start docker
echo "➜ starting docker-compose"
dc up -d
elif [ $serviceName = "spring" ]; then
start mongo
echo "➜ starting spring-boot"
mvn spring-boot:run
elif [ $serviceName = "container" ]; then
containerName=$2;
containerInfo="[port:$(docker port $containerName) volume:$(docker inspect -f '{{index (.HostConfig.Binds) 0}}' $containerName)]"
containerIsRunning="$(docker inspect -f '{{.State.Running}}' $containerName 2>/dev/null)"
containerStatus="$(docker inspect -f '{{.State.Status}}' $containerName 2>/dev/null)"
if [ $containerIsRunning = "true" ]; then
echo "$containerName already running $containerInfo"
elif [ $containerStatus = "exited" ]; then
echo "➜ running $containerName $containerInfo"
echo "➜ id:$(sudo docker start $containerName)"
else
echo "➜ container $containerName $containerInfo doesnt exist"
fi
elif [ $serviceName = "dc" ]; then
start docker
echo "➜ starting docker-compose"
dc up -d
fi
}

22
zsh/functions/wp.zsh Normal file
View File

@ -0,0 +1,22 @@
# Helps navigating wordpress directory
function wp(){
first_dir=${1%/*}
second_dir=${1#*/}
if [ $first_dir = $second_dir ]; then
second_dir=""
fi
if [ $first_dir = "plugins" ]; then
cd "wp-content/plugins"
elif [ $first_dir = "themes" ]; then
cd "wp-content/themes"
fi
if [ $second_dir != "" ]; then
fi
}