Merge branch '1-add-support-for-openbsd-in-autoattach-script' into 'master'

Resolve "Add support for OpenBSD  in autoattach script."

Closes #1

See merge request lhprojects-information-network/scripts!1
This commit is contained in:
Lutchy Horace 2021-01-26 04:24:02 -05:00
commit 96619c8183
1 changed files with 16 additions and 14 deletions

View File

@ -7,7 +7,7 @@ CONF_FILE=$HOME/.autoattach.conf
########################### ###########################
function write_setting function write_setting
{ {
if ! sed -i -E "s/^$1=.*/$1=$2/" $CONF_FILE 2> /dev/null; then if ! sed -i -E "s/^$1=.*/$1=$2/" $CONF_FILE 2> /dev/null; then
echo "$1=$2" >> $CONF_FILE echo "$1=$2" >> $CONF_FILE
@ -20,34 +20,34 @@ function attach_session
if [ -n "${TMUX}" ]; then if [ -n "${TMUX}" ]; then
exit 1 exit 1
fi fi
tmux attach -t $1 2> /dev/null tmux attach -t $1 2> /dev/null
# Check for exit status # Check for exit status
if [ $? -gt 0 ]; then if [ $? -gt 0 ]; then
echo "There is no tmux session '$1'" echo "There is no tmux session '$1'"
if [ -z "${AUTO_CREATE}" ]; then if [ -z "${AUTO_CREATE}" ]; then
read -p "Do you want me to auto create sessions by default? (y/n): " read -p "Do you want me to auto create sessions by default? [Y/n]: "
if [ "${REPLY}" = "y" ]; then if [ "${REPLY}" = "y" -o -z "${REPLY}" ]; then
write_setting 'AUTO_CREATE' '1' write_setting 'AUTO_CREATE' '1'
AUTO_CREATE=1 AUTO_CREATE=1
else else
write_setting 'AUTO_CREATE' '0' write_setting 'AUTO_CREATE' '0'
fi fi
fi fi
if [ "${AUTO_CREATE}" = "1" ]; then if [ "${AUTO_CREATE}" = "1" ]; then
tmux new-session -s $1 2> /dev/null tmux new-session -s $1 2> /dev/null
exit 0 exit 0
fi fi
echo 'Nothing to do, exiting...' echo 'Nothing to do, exiting...'
exit 1 exit 1
fi fi
} }
function usage function usage
{ {
echo "Usage: ${0}" echo "Usage: ${0}"
echo " -c | --clear" echo " -c | --clear"
echo " Delete configuration file" echo " Delete configuration file"
@ -66,13 +66,15 @@ function usage
test -f $CONF_FILE && . $CONF_FILE test -f $CONF_FILE && . $CONF_FILE
# Detect platform # Detect platform
case "$OSTYPE" in PLATFORM='unknown'
freebsd* ) unamestr=$(uname)
echo "Freebsb detected!!" case "$unamestr" in
OpenBSD* )
echo "*BSD OS detected!!"
echo "Long options is disabled!!" echo "Long options is disabled!!"
OPTS=`getopt chgs: $*` OPTS=`getopt chgs: $*`
set_opts_exit_status=$? set_opts_exit_status=$?
PLATFORM='Freebsd' ;; PLATFORM=$unamestr ;;
#if [ $? -ne 0 ]; then #if [ $? -ne 0 ]; then
# echo 'Usage: ...' # echo 'Usage: ...'
# exit 2 # exit 2
@ -108,7 +110,7 @@ while true; do
write_setting 'AUTO_CREATE' '0' write_setting 'AUTO_CREATE' '0'
shift;; shift;;
esac esac
shift;; shift;;
*) *)
echo "Failed to set configuration $2 $4" echo "Failed to set configuration $2 $4"