myshellconfig/myshell_load_defaults

157 lines
4.4 KiB
Text
Raw Normal View History

#!/bin/bash
# if we are root, exit after 5 Minutes
2020-03-12 18:26:04 +01:00
case $(tty) in
/dev/tty[0-9]*)
#[ $( id -u ) -eq 0 ] && TMOUT=${MYSHELLCONFIG_ROOT_TMOUT}
#[ $( id -u ) -gt 0 ] && TMOUT=${MYSHELLCONFIG_USER_TMOUT}
2020-03-12 21:34:23 +01:00
case $(id -u) in
0)
2020-03-12 20:59:57 +01:00
TMOUT=${MYSHELLCONFIG_ROOT_TMOUT:-500}
;;
*)
2020-03-12 20:59:57 +01:00
TMOUT=${MYSHELLCONFIG_USER_TMOUT:-0}
;;
esac
2020-03-12 18:27:38 +01:00
echo "Run in TTY -> set autologout \$TMOUT=$TMOUT" >&2
2020-03-12 18:26:04 +01:00
;;
*)
echo "Run in other terminal" >&2
;;
esac
# Load default values, functions, aliases for myshellconfig
if ! $SSHS; then
if [ -e ${MYSHELLCONFIG_BASE}/functions.sh ]; then
. ${MYSHELLCONFIG_BASE}/functions.sh
else
return
fi
######################################################################################
# ls is not in color on all systems
export LS_OPTIONS='--color=auto'
eval "`dircolors`"
#######################################################################################
# User specific aliases and function
if [ -d "${MYSHELLCONFIG_BASE}/bin" ] ; then
pathmunge "${MYSHELLCONFIG_BASE}/bin"
export PATH
fi
if [ -d "${MYSHELLCONFIG_BASE}/git-credential-pass" ] ; then
pathmunge "${MYSHELLCONFIG_BASE}/git-credential-pass"
export PATH
fi
if [ -f "${MYSHELLCONFIG_BASE}/aliases" ]; then
. "${MYSHELLCONFIG_BASE}/aliases"
fi
if [ -f "${MYSHELLCONFIG_BASE}/PS1" ]; then
. "${MYSHELLCONFIG_BASE}/PS1"
fi
if [ -e "${MYSHELLCONFIG_BASH_COMPLETION}" ]; then
for i in $( ls "${MYSHELLCONFIG_BASH_COMPLETION}" ); do
. "${MYSHELLCONFIG_BASH_COMPLETION}/${i}"
done
fi
2020-01-22 11:00:53 +01:00
if [ -f "${MYSHELLCONFIG_BASE}/myshell_load_fortmpconfig" ]; then
2020-01-22 10:47:19 +01:00
. "${MYSHELLCONFIG_BASE}/myshell_load_fortmpconfig"
fi
#########################################################################################
# Go HOME
#cd ${HOME}
if test ! $TMUX && test $SSH_TTY && test $TERM != screen && test $(systemctl status tmux@${USER}.service 1>/dev/null 2>&1; echo $? ) -eq 0; then
cat << EOF
"User: $USER - $UID"
Starting or resuming screen session
Press CTRL+C to cancel screen startup
EOF
sleep 1
#screen -UxR
tmux attach-session
fi
unset -f pathmunge
else
# run with temporary config
case $TERM in
*screen*)
echo BASHRC: $BASHRC -> source it
#[ -e $BASHRC ] && . "$BASHRC"
if [ ! -z ${BASHRC+x} ]; then
if [ -e $BASHRC ] ; then
exec bash --rcfile "$BASHRC" -i /dev/null
else
exec bash -i
fi
else
exec bash -i
fi
;;
esac
fi
2020-01-22 10:10:10 +01:00
# Create and link Work-Dir of the Day
2020-02-11 16:13:14 +01:00
#if [ $(id -u) -ne 0 ]; then
# ARCHIVSUBPATH="archive/work"
# ARCHIVPATH="${HOME}/${ARCHIVSUBPATH}"
# WDOTD=$(date "+${ARCHIVPATH}/%Y/%m/work_%Y%m%d")
# WORKDIR="${HOME}/Work"
#
# # First cleanup all empty Archivdirectories for workdir
# for i in $(find ${ARCHIVPATH} -maxdepth 3 -type d |grep -v "$WDOTD" ); do
# if [ ! "$(ls -A $i)" ]; then
# echo "DIR $i is empty -> remove it" >&2
# rm -vr "$i" 2>&1 |tee -a ${MYSHELLCONFIG_LOGFILE} >&2
# fi
# done
#
# # Create workdir of the day, if not existing
# [ -e $WDOTD ] || mkdir -pv "${WDOTD}" >>${MYSHELLCONFIG_LOGFILE}
#
# # Link $WORKDIR to $WDOTD and set alias
# if [[ ( -e "${WORKDIR}" && -h "${WORKDIR}" ) || ! -e "${WORKDIR}" ]] ; then
# ln -svnf "${WDOTD}" "${WORKDIR}" >>${MYSHELLCONFIG_LOGFILE}
# alias gowork='cd "${WORKDIR}"'
# else
# echo "${WORKDIR} exists and is real directory" |tee -a ${MYSHELLCONFIG_LOGFILE} 2>&1
# alias gowork='echo "${WORKDIR} is not configurable, see ${MYSHELLCONFIG_LOGFILE}'
# fi
#
# unset ARCHIVPATH ARCHIVSUBPATH
#fi
2020-01-22 10:10:10 +01:00
2020-02-12 12:21:26 +01:00
# Disable Ctrl+s to freeze terminal
# Source https://www.digitalocean.com/community/tutorials/how-to-use-bash-history-commands-and-expansions-on-a-linux-vps
stty -ixon
export HISTCONTROL=erasedups:ignorespace:ignoredups
2020-02-17 20:16:34 +01:00
export HISTIGNORE="ls:l:cd:exit:pwd:date:mencfs:"
2020-02-13 06:39:02 +01:00
export HISTTIMEFORMAT='%F %T '
2020-02-13 06:40:21 +01:00
export HISTSIZE=999999
2020-01-22 10:10:10 +01:00
2020-01-22 10:22:05 +01:00
echo "bashrc_add sourced" 2>&1 |tee -a ${MYSHELLCONFIG_LOGFILE} >&2
#echo "bashrc_add sourced" >&2
2020-01-22 10:10:10 +01:00