From 3d3e3ddd5ffc137bc9637709272298210aa94dd7 Mon Sep 17 00:00:00 2001 From: Lutchy Horace Date: Tue, 26 Jan 2021 04:21:38 -0500 Subject: [PATCH] Support for different flavors of BSD systems. --- autoattach | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/autoattach b/autoattach index 4a9bea7..9179920 100755 --- a/autoattach +++ b/autoattach @@ -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"