fixed execution order bug that was causing the first two frame numbers to output...
[puredata.git] / scripts / config-switcher.sh
blobb8f29130c3f69bf9af3fa7dde2b2a38e7c2ff425
1 #!/bin/sh
4 #==============================================================================#
5 # functions
7 print_usage() {
8 echo "Usage: "
9 echo "To load a config file:"
10 echo " $0 load CONFIG_NAME"
11 echo " "
12 echo "To save the current config to file:"
13 echo " $0 save CONFIG_NAME"
14 echo " "
15 echo "To delete the current config:"
16 echo " $0 delete CONFIG_NAME"
17 echo " "
18 echo "To list existing configs:"
19 echo " $0 list"
20 echo " "
21 echo "To print the contents of a config:"
22 echo " $0 print CONFIG_NAME"
23 echo " "
24 echo "To see the difference between the current config and another:"
25 echo " $0 diff CONFIG_NAME"
26 echo " "
27 echo "To use the .pdrc instead, add '--pdrc':"
28 echo " $0 --pdrc load CONFIG_NAME"
29 echo " $0 --pdrc save CONFIG_NAME"
30 echo " $0 --pdrc delete CONFIG_NAME"
31 echo " $0 --pdrc list"
32 echo " $0 --pdrc print CONFIG_NAME"
33 echo " $0 --pdrc diff CONFIG_NAME"
34 exit
37 #==============================================================================#
38 # THE PROGRAM
40 if [ $# -lt 1 ]; then
41 print_usage
42 else
43 # get the command line arguments
44 if [ $1 == "--pdrc" ]; then
45 CONFIG_DIR=~
46 CONFIG_FILE=.pdrc
47 COMMAND=$2
48 CONFIG_NAME=$3
49 else
50 COMMAND=$1
51 CONFIG_NAME=$2
52 # location of pref file that Pd reads
53 case `uname` in
54 Darwin)
55 CONFIG_DIR=~/Library/Preferences
56 CONFIG_FILE=org.puredata.pd.plist
58 Linux)
59 CONFIG_DIR=~
60 CONFIG_FILE=.pdsettings
63 echo "Not supported on this platform."
64 exit
66 esac
69 # everything happens in this dir
70 cd $CONFIG_DIR
72 selected_file="$CONFIG_DIR/$CONFIG_FILE-$CONFIG_NAME"
73 case $COMMAND in
74 load)
75 if [ -e "$selected_file" ]; then
76 test -e "$CONFIG_FILE" && mv -f "$CONFIG_FILE" /tmp
77 cp "$selected_file" "$CONFIG_FILE" && \
78 echo "Pd config \"$selected_file\" loaded."
79 else
80 echo "\"$selected_file\" doesn't exist. No action taken."
83 save)
84 if [ -e "$CONFIG_FILE" ]; then
85 cp -f "$CONFIG_FILE" "$selected_file" && \
86 echo "Pd config \"$CONFIG_NAME\" saved."
87 else
88 echo "\"$CONFIG_FILE\" doesn't exist. No action taken."
91 delete)
92 if [ -e "$selected_file" ]; then
93 rm -f "$selected_file" && \
94 echo "Pd config \"$selected_file\" deleted."
95 else
96 echo "\"$selected_file\" doesn't exist. No action taken."
99 list)
100 echo "Available configs:"
102 ls -1 "${CONFIG_FILE}"*
105 print)
106 if [ "${CONFIG_NAME}" == "" ]; then
107 cat "${CONFIG_FILE}"
108 else
109 cat "$selected_file"
112 diff)
113 diff -uw "${CONFIG_FILE}" "$selected_file"
115 *) print_usage ;;
116 esac