started using chezmoi
This commit is contained in:
parent
bd6a70961d
commit
8241382382
6 changed files with 447 additions and 0 deletions
102
dot_config/zsh/direnv.zsh
Normal file
102
dot_config/zsh/direnv.zsh
Normal file
|
@ -0,0 +1,102 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
autoload colors is-at-least
|
||||
|
||||
BOLD="bold"
|
||||
NONE="NONE"
|
||||
|
||||
[[ -z "$DIRENV_HOME" ]] && export DIRENV_HOME="$HOME/.config/direnv"
|
||||
|
||||
ZSH_DIRENV_VERSION_FILE=${DIRENV_HOME}/version.txt
|
||||
|
||||
_zsh_direnv_log() {
|
||||
local font=$1
|
||||
local color=$2
|
||||
local msg=$3
|
||||
|
||||
if [ $font = $BOLD ]
|
||||
then
|
||||
echo $fg_bold[$color] "[zsh-direnv-plugin] $msg" $reset_color
|
||||
else
|
||||
echo $fg[$color] "[zsh-direnv-plugin] $msg" $reset_color
|
||||
fi
|
||||
}
|
||||
|
||||
_zsh_direnv_last_version() {
|
||||
echo $(curl -s https://api.github.com/repos/direnv/direnv/releases | grep tag_name | head -n 1 | cut -d '"' -f4)
|
||||
}
|
||||
|
||||
_zsh_direnv_download_install() {
|
||||
local version=$1
|
||||
local machine
|
||||
case "$(uname -m)" in
|
||||
x86_64)
|
||||
machine=amd64
|
||||
;;
|
||||
i686 | i386)
|
||||
machine=386
|
||||
;;
|
||||
aarch64)
|
||||
machine=arm64
|
||||
;;
|
||||
*)
|
||||
_zsh_direnv_log $BOLD "red" "Machine $(uname -m) not supported by this plugin"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
_zsh_direnv_log $NONE "blue" " -> download and install direnv ${version}"
|
||||
wget -qc --no-check-certificate https://github.com/direnv/direnv/releases/download/${version}/direnv.${OSTYPE%-*}-${machine} -O "${DIRENV_HOME}/direnv"
|
||||
chmod +x "${DIRENV_HOME}/direnv"
|
||||
echo ${version} > ${ZSH_DIRENV_VERSION_FILE}
|
||||
}
|
||||
|
||||
_zsh_direnv_install() {
|
||||
_zsh_direnv_log $NONE "blue" "#############################################"
|
||||
_zsh_direnv_log $BOLD "blue" "Installing direnv..."
|
||||
_zsh_direnv_log $NONE "blue" "-> creating direnv home dir : ${DIRENV_HOME}"
|
||||
mkdir -p ${DIRENV_HOME} || _zsh_direnv_log $NONE "green" "dir already exist"
|
||||
local last_version=$(_zsh_direnv_last_version)
|
||||
_zsh_direnv_log $NONE "blue" "-> retrieve last version of direnv..."
|
||||
_zsh_direnv_download_install ${last_version}
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
_zsh_direnv_log $BOLD "red" "Install KO"
|
||||
else
|
||||
_zsh_direnv_log $BOLD "green" "Install OK"
|
||||
fi
|
||||
_zsh_direnv_log $NONE "blue" "#############################################"
|
||||
}
|
||||
|
||||
update_zsh_direnv() {
|
||||
_zsh_direnv_log $NONE "blue" "#############################################"
|
||||
_zsh_direnv_log $BOLD "blue" "Checking new version of direnv..."
|
||||
|
||||
local current_version=$(cat ${ZSH_DIRENV_VERSION_FILE})
|
||||
local last_version=$(_zsh_direnv_last_version)
|
||||
|
||||
if is-at-least ${last_version#v*} ${current_version#v*}
|
||||
then
|
||||
_zsh_direnv_log $BOLD "green" "Already up to date, current version : ${current_version}"
|
||||
else
|
||||
_zsh_direnv_log $NONE "blue" "-> Updating direnv..."
|
||||
_zsh_direnv_download_install ${last_version}
|
||||
_zsh_direnv_log $BOLD "green" "Update OK"
|
||||
fi
|
||||
_zsh_direnv_log $NONE "blue" "#############################################"
|
||||
}
|
||||
|
||||
_zsh_direnv_load() {
|
||||
# export PATH
|
||||
export PATH=${PATH}:${DIRENV_HOME}
|
||||
eval "$(direnv hook zsh)"
|
||||
}
|
||||
|
||||
# install direnv if it isnt already installed
|
||||
[[ ! -f "${ZSH_DIRENV_VERSION_FILE}" ]] && _zsh_direnv_install
|
||||
|
||||
# load direnv if it is installed
|
||||
if [[ -f "${ZSH_DIRENV_VERSION_FILE}" ]]; then
|
||||
_zsh_direnv_load
|
||||
fi
|
||||
|
||||
unset -f _zsh_direnv_install _zsh_direnv_load
|
31
dot_config/zsh/sshagent.zsh
Normal file
31
dot_config/zsh/sshagent.zsh
Normal file
|
@ -0,0 +1,31 @@
|
|||
SSH_ENV="$HOME/.ssh/environment"
|
||||
KEY="$HOME/.ssh/id_rsa"
|
||||
|
||||
function start_agent () {
|
||||
ssh-agent -s | sed 's/^echo/#echo/' > "$SSH_ENV"
|
||||
chmod 600 "$SSH_ENV"
|
||||
. "$SSH_ENV" > /dev/null
|
||||
}
|
||||
|
||||
function add_identities () {
|
||||
ssh-add -l | grep "The agent has no identities" > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
ssh-add $KEY &> /dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
function is_ssh_agent_pid_valid () {
|
||||
ps -ef | grep $1 | grep -v grep | grep ssh-agent > /dev/null
|
||||
}
|
||||
|
||||
if [ -n "$SSH_AGENT_PID" ] && is_ssh_agent_pid_valid $SSH_AGENT_PID; then
|
||||
add_identities
|
||||
else
|
||||
if [ -f "$SSH_ENV" ]; then
|
||||
. "$SSH_ENV" > /dev/null
|
||||
fi
|
||||
if ! is_ssh_agent_pid_valid $SSH_AGENT_PID; then
|
||||
start_agent
|
||||
fi
|
||||
add_identities
|
||||
fi
|
4
dot_config/zsh/starship.toml
Normal file
4
dot_config/zsh/starship.toml
Normal file
|
@ -0,0 +1,4 @@
|
|||
add_newline = false
|
||||
|
||||
[time]
|
||||
disabled = false
|
Loading…
Add table
Add a link
Reference in a new issue