Multi-Machine STATUS Check

From Gwen Morse's Wiki
Jump to: navigation, search

Tinyfugue Multi-Machine Status Check

I'll provide a brief explanation as to philosophy behind this code. The expected .tfrc configuration is to break macros up into different categories and store each category in its own file. That's all well and good unless you update your macros frequently and also run Tinyfugue on multiple computers. Then it becomes more difficult to keep everything synced.

I use the cloud storage service Dropbox to sync my Tinyfugue files. You could also use rsync, a NAS, or similar options. I leave everything in one document and simply run a check at the top of the file to determine the specific computer I'm using.

Each computer has to have a unique characteristic to determine which one it is. Each "status" setting has to be unique. BASEOS does not need to be unique and is most commonly used to check if I can call shell scripts using /sh (/sh is broken on the Windows build of Tinyfugue).

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Multi-Machine Status check
;;; Written by Gwen Morse 
;;;
;;; Enter the directories where you keep your tf files.
;;; Home directory if-else help from "Sizer" <sizer at san dot rr dot com>
;;; The if-else check is to see 'which' machine I am running TF on.
;;; I do this because I use TF on multiple machines and OS-es.
;;; That way, I can copy one tfrc file between multiple machines
;;; rather than try to maintain separate files with specific code for each.
;;;
;;; I make use of the "STATUS" definition in later macros to determine
;;; "which" machine I'm on.
;;;
;;; That way, I can copy one tfrc file between multiple machines
;;; rather than try to maintain separate files with specific code for each.
;;;
;;; COMPNAME is the name of the computer in Windows (usually found in the My Computer/Properties tab)
;;; HOME is the home directory (on linux or windows type /cd in tinyfugue to get the exact home path)
;;; the HOME path of /arpa/gm/g/goldmoon is my free sdf.org shell account.
;;; the HOME path of /home/user is on my n900 tablet phone
;;; the /else option is the settings for running Tinyfugue off my USB stick.
;;;
;;;
;;; With a little bit of examination you can see how to provide per-machine configuration settings.
;;; For example, I used to only use the n900 and USB stick in locations where syntax highlighting would
;;; call attention to my activities. For those two connections, I turned off colors to be less obtrusive.
;;;
;;; On the n900, the enter button on the physical keyboard sends the code for a numeric keypad enter. To get it 
;;; to work properly, you have to force it to send a NEWLINE. The n900 has a 3.75" 800x480 screen which
;;; doesn't allow for as many 'lines' of text as a laptop or desktop. I find an isize of 2 works best for me.
;;;
;;; When running from USB stick the system can't find my ruby libraries. I set it by hand using
;;; the built in /setenv.
;;; 
;;; This should show how, with a little bit of effort, you can use the same config file on multiple computers

;; This is set up here so I can change it on specific machines as needed.
/set isize=5

/if (HOME=~"/arpa/gm/g/goldmoon")\
    /cd /arpa/gm/g/goldmoon/%;\
    /def LOGDIR=/arpa/gm/g/goldmoon/logs %;\
    /set DECDIR=/arpa/gm/g/goldmoon/logs/decompile %;\
    /set status=arpa%;\
    /set BASEOS=linux%;\
/elseif (HOME=~"/home/user")\
    /cd /home/user/MyDocs/DropN900/Tinyfugue/ %;\
    /def LIBDIR=/usr/share/tf-lib %;\
    /def LOGDIR=/home/user/MyDocs/DropN900/Tinyfugue/logs %;\
    /def DECDIR=/home/user/MyDocs/DropN900/Tinyfugue/logs/decompile %;\
    /set status=n900%;\
    /def key_nkpEnt = /dokey NEWLINE%;\
    /set isize=2%;\
    /color_off%;\
    /set BASEOS=linux%;\
/elseif (COMPNAME=~"MS_PIGGY")\
    /cd /cygdrive/c/Users/gwen/Tinyfugue%;\
    /set LIBDIR=/cygdrive/c/Users/gwen/Tinyfugue/tf-lib%;\
    /def LOGDIR=/cygdrive/d/Dropbox/Tinyfugue/logs%;\
    /set DECDIR=/cygdrive/d/Dropbox/Tinyfugue/logs/decompile%;\
    /set SHELL=rxvt%;\
    /set status=piggy%;\
    /set BASEOS=windows%;\
/else \
    /cd /cygdrive/f/Tf%;\
    /def LOGDIR=/cygdrive/f/Tf/logs%;\
    /def LIBDIR=/cygdrive/f/Tf/locallib%;\
    /setenv RUBYLIB=/cygdrive/f/Tf/ruby/1.8/%;\
    /setenv SHELL=/cygdrive/f/Tf/bash.exe%;\
    /color_off%;\
    /set status=usb%;\
    /set BASEOS=windows%;\
/endif

Some extra little tricks (per machine)

;;; set 256 color variable
;;; This is an "or" check for if/else, so either will match.
/if (TERM =~ "xterm-256color" | SHELL =~ "rxvt" )\
  /set COLORS=265%;\
/else \
  /set COLORS=16%;\
/endif%;\
;;;;;;;;;;;;;;;;;;;;;;
;; Sneaky world system
;; If you have multiple computers you play from, and you have a character
;; (or characters) that you only want to be able to play from a specific account.
;; (Stealth RP!)
;; You can use a modified form of the below macro (coupled with the {status} macro
;; shown earlier) to only add world(s) when you're on the 'correct' account.

/def -F tsc=\
  /if ({status}=~"winbox") \
    /addworld -T"tiny.mush" tsc palemoon.com 9990 %;\
  /endif
/tsc
;;;;;;;;;;;;;;;;;;;;

Autologging Per Machine

;;; Logs will overwrite each other if they have the exact same name and are synced from
;;; different machines. This macro will slightly change the names of logs
;;; to make them unique on each machine.
;;; Below are three sample 'status' choices plus an 'else' for 'everything else'.
;;; This version includes the multi-machine 'status' check:

/def -Fp100 -h'connect' connect_log = \
/if ({status}=~"usb") \
  /log -w ${LOGDIR}/$[ftime("%Y",time())]/$[ftime("%Y-%m-%d", time())]_u_${world_name}.log %;\
  /eval /echo -ag -w${world_name} \
%============================================================================== %;\
  /eval /echo -ag -w${world_name} \
%=            Log for world *** ${world_name} ***, started $(/time %%c) %;\
  /eval /echo -ag -w${world_name} \
%============================================================================== %;\
/elseif ({status}=~"arpa") \
  /log -w ${LOGDIR}/$[ftime("%Y",time())]/$[ftime("%Y-%m-%d", time())]_a_${world_name}.log %;\
  /eval /echo -ag -w${world_name} \
%============================================================================== %;\
  /eval /echo -ag -w${world_name} \
%=            Log for world *** ${world_name} ***, started $(/time %%c) %;\
  /eval /echo -ag -w${world_name} \
%============================================================================== %;\
/elseif ({status}=~"n900") \
  /log -w ${LOGDIR}/$[ftime("%Y",time())]/$[ftime("%Y-%m-%d", time())]_n_${world_name}.log %;\
  /eval /echo -ag -w${world_name} \
%============================================================================== %;\
  /eval /echo -ag -w${world_name} \
%=            Log for world *** ${world_name} ***, started $(/time %%c) %;\
  /eval /echo -ag -w${world_name} \
%============================================================================== %;\
/else \
  /log -w ${LOGDIR}/$[ftime("%Y",time())]/$[ftime("%Y-%m-%d", time())]_v_${world_name}.log %;\
  /eval /echo -ag -w${world_name} \
%============================================================================== %;\
  /eval /echo -ag -w${world_name} \
%=            Log for world *** ${world_name} ***, started $(/time %%c) %;\
  /eval /echo -ag -w${world_name} \
%============================================================================== %;\
/endif

; Lets /dc function like 'QUIT' to trigger the disconnect (needed to close the log)
; written by 'Brack <slayer at kaiwan dot com>'

/def -F -1ag -h'conflict' gagconflict
/def -Fiq dc = /if /@dc %*%; /then /trigger -hdisconnect %*%; /endif

; This lets you return to the special logging after shutting it off with /log off.
; Note, if the original special log was during the previous calendar 'day', then,
; /relog will start a new log!
;
; Syntax: '/relog'

/def -i -q relog = /connect_log

;This is the disconnect function, noting the time the log ended and closing the file.

/def -Fp100 -h'disconnect' disconnect_log = \
  /eval /echo -ag -w${world_name} \
%============================================================================== %;\
  /eval /echo -ag -w${world_name} \
%=            Log for world *** ${world_name} ***, ended $(/time %%c) %;\
  /eval /echo -ag -w${world_name} \
%============================================================================== %;\
  /log -w${world_name} off