Re: xterm: restore env after restart

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On KDE start, how to restore your xterms running bash to the state
they had at the previous KDE shutdown (well, mostly).

Needed an xterm script file used when you explicitly launch xterm and
a bash file used to save/restore each xterm's bash session.

mkdir $HOME/.bash_info



xterm script:

#!/bin/bash

export BASH_INFO="$HOME/.bash_info"

# find new id
declare -i BASH_ID=0
while [[ -e $BASH_INFO/xterm_$BASH_ID ]]; do
    BASH_ID=$(( $BASH_ID + 1))
done

# make unique directory based upon bash id
/bin/mkdir $BASH_INFO/xterm_$BASH_ID

# store bash id in file
LOCAL_INIT_FILE=" $BASH_INFO/xterm_$BASH_ID/LOCAL_INIT_FILE"
echo "# LOCAL_INIT_FILE" >  $LOCAL_INIT_FILE
echo "export BASH_ID=$BASH_ID" >>  $LOCAL_INIT_FILE
echo "export BASH_INFO=$HOME/.bash_info" >> $LOCAL_INIT_FILE
echo ". $BASH_INFO/INIT_FILE" >>  $LOCAL_INIT_FILE

# start xterm
/usr/bin/xterm  -bg lightgrey \
    -geometry 80x22 -sl 1500 +si \
    -fa $F -fs 12 \
     -e /bin/bash --init-file $LOCAL_INIT_FILE &

# end-of-script


xterm initialization script:

# INIT_FILE

. $HOME/.bashrc

XTERM_DIR=$BASH_INFO/xterm_$BASH_ID
export HISTFILE=$XTERM_DIR/history
export HISTSIZE=1000


if [[ -f $XTERM_DIR/CD_FILE ]]; then
   . $XTERM_DIR/CD_FILE
fi

function cd() {
    if [[ $# -eq 0 ]]; then
        builtin cd
    else
        builtin cd "$1"
    fi
    echo "cd $PWD" > $XTERM_DIR/CD_FILE
}

function on_exit() {
    echo "cd $PWD" > $XTERM_DIR/CD_FILE
    builtin exit 0
}

trap on_exit SIGTERM EXIT
# restart vi command if found
if [[ -e $HISTFILE ]]; then
    CMD=$(tail -1 $HISTFILE)
    #echo CMDO=$CMD
    if [[ "$CMD" == "exit" ]]; then
        CMD=$(tail -2 $HISTFILE | grep -v exit)
    fi
    if [[ "$CMD" == "exit" ]]; then
        CMD=$(tail -3 $HISTFILE | grep -v exit)
    fi
    #echo CMD1=$CMD
    if [[ $CMD =~ "vi" ]]; then
        eval $CMD
    fi
fi
# end-of-script


Now launch your xterms using above xterm script.
If you do a:
ps auxwww | grep xterm

you will see the running xterm commands which are the same commands
that will be stored in the KDE session manager rc file:

$HOME/.kde/share/config/ksmserverrc

so that when KDE restarts, your xterms will restart in the same
directories and vi sessions that you left them in.

If there is a better way, please post it. Thanks


Richard




Richard Emberson wrote:

I am an xterm kind of guy, I have multiple virtual desktops with
multiple xterms per desktop. When I stop and then restart KDE
(maybe because I have to reboot, new kernel, etc.) I get all
of the xterms, then all come up, but not with their environments.
The xterms are all created which the bash shell in my home
directory. What I want is for each xterm to be in the directory
where it was when I rebooted with the same command history.

Does anyone know how to do this (and share that info)?
thanks

Richard





--
This email message is for the sole use of the intended recipient(s) and
may contain confidential information.  Any unauthorized review, use,
disclosure or distribution is prohibited.  If you are not the intended
recipient, please contact the sender by reply email and destroy all
copies of the original message.

--
fedora-devel-list mailing list
fedora-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/fedora-devel-list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Fedora Announce]     [Fedora Kernel]     [Fedora Testing]     [Fedora Formulas]     [Fedora PHP Devel]     [Kernel Development]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Gimp]     [Yosemite News]
  Powered by Linux