Support for different flavors of BSD systems.

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