| 1 |
# Preferences functions - used for storing and loading user preferences |
| 2 |
|
| 3 |
# Crystal needs ~/.fvwm/preferences/ directory to store the preferences files. |
| 4 |
# |
| 5 |
Exec mkdir -p $[FVWM_USERDIR]/preferences |
| 6 |
|
| 7 |
# This function saves specified command in a file, in the user's preferences |
| 8 |
# directory (~/.fvwm/preferences/). It can be used to store FVWM commands, so |
| 9 |
# they can be executed at next startup, useful for saving user-configurable |
| 10 |
# preferences, like used colorset or window decoration. |
| 11 |
# |
| 12 |
# Usage: |
| 13 |
# SavePreferences <preferences-file> "<command>" |
| 14 |
# |
| 15 |
# Example: |
| 16 |
# SavePreferences PreferencesFile "Echo \"FVWM command\"" |
| 17 |
# |
| 18 |
DestroyFunc SavePreferences |
| 19 |
AddToFunc SavePreferences |
| 20 |
+ I Exec echo "$1" > $[FVWM_USERDIR]/preferences/$0 |
| 21 |
|
| 22 |
# Modification of SavePreferences: add more lines to the preferences file |
| 23 |
# Must be used in conjonction with Schedule or the synchronization will be lost |
| 24 |
# |
| 25 |
# Exemple: |
| 26 |
# SavePreferences PreferencesFile "Echo \"FVWM command\"" |
| 27 |
# Schedule 333 AppendPreferences PreferencesFile OtherCommand |
| 28 |
# |
| 29 |
DestroyFunc AppendPreferences |
| 30 |
AddToFunc AppendPreferences |
| 31 |
+ I Exec touch $[FVWM_USERDIR]/preferences/$0 |
| 32 |
+ I Exec echo $1 >> $[FVWM_USERDIR]/preferences/$0 |
| 33 |
|
| 34 |
# add or update one line into the preferences file |
| 35 |
# |
| 36 |
# UpdateAppendPreferences <preferences-file> "<command>" "<begining of the line>" |
| 37 |
# where <begining of the line> must be unique into the file. |
| 38 |
DestroyFunc UpdateAppendPreferences |
| 39 |
AddToFunc UpdateAppendPreferences |
| 40 |
+ I Exec touch $[FVWM_USERDIR]/preferences/"$0" |
| 41 |
+ I PipeRead 'mv $[FVWM_USERDIR]/preferences/"$0" $[FVWM_USERDIR]/preferences/"$0".tmp; \ |
| 42 |
sed "/^$2.*/d" $[FVWM_USERDIR]/preferences/"$0".tmp > $[FVWM_USERDIR]/preferences/"$0"; \ |
| 43 |
rm $[FVWM_USERDIR]/preferences/"$0".tmp; \ |
| 44 |
echo "$1" >> $[FVWM_USERDIR]/preferences/"$0"' |
| 45 |
|
| 46 |
# This function looks for saved preferences file and reads it. All directories |
| 47 |
# (user-wide, system-wide, package-wide) are searched, first file found is |
| 48 |
# loaded. |
| 49 |
# |
| 50 |
# Example: |
| 51 |
# LoadPreferences PreferencesFile |
| 52 |
# |
| 53 |
DestroyFunc LoadPreferences |
| 54 |
AddToFunc LoadPreferences |
| 55 |
+ I Test (f $[FVWM_USERDIR]/preferences/$0) Read $[FVWM_USERDIR]/preferences/$0 |
| 56 |
+ I TestRc (NoMatch) Test (f $[FVWM_CONFIGDIR]/preferences/$0) Read $[FVWM_CONFIGDIR]/preferences/$0 |
| 57 |
+ I TestRc (NoMatch) Test (f $[FVWM_SYSTEMDIR]/preferences/$0) Read $[FVWM_SYSTEMDIR]/preferences/$0 |
| 58 |
|
| 59 |
# This function looks for specified preferences file, if it is present, |
| 60 |
# nothing is done. If it's not found, specified command is executed. This can |
| 61 |
# be used to check if there are "default" preferences, and in case they aren't |
| 62 |
# there, set a default ones. |
| 63 |
# |
| 64 |
# Usage: |
| 65 |
# CheckPreferences <preferences-file> "<command>" |
| 66 |
# |
| 67 |
# Example: |
| 68 |
# CheckPreferences PreferencesFile 'SavePreferences PreferencesFile "Echo \"FVWM command\""' |
| 69 |
# |
| 70 |
DestroyFunc CheckPreferences |
| 71 |
AddToFunc CheckPreferences |
| 72 |
+ I Test (f $[FVWM_USERDIR]/preferences/$0) Break |
| 73 |
+ I Test (f $[FVWM_CONFIGDIR]/preferences/$0) Break |
| 74 |
+ I Test (f $[FVWM_SYSTEMDIR]/preferences/$0) Break |
| 75 |
+ I $1 |
| 76 |
|
| 77 |
# This function looks for specified preference file in the user-wide directory. |
| 78 |
# If it's found, nothing is done, if it's not found, the first file found |
| 79 |
# in the config-wide or system-wide directories is copied to the user-wide |
| 80 |
# directory. |
| 81 |
# |
| 82 |
# Example: See below. |
| 83 |
# |
| 84 |
DestroyFunc CopyPreferences |
| 85 |
AddToFunc CopyPreferences |
| 86 |
+ I Test (f $[FVWM_USERDIR]/preferences/$0) Break |
| 87 |
+ I Test (f $[FVWM_CONFIGDIR]/preferences/$0) Exec exec cp $[FVWM_CONFIGDIR]/preferences/$0 $[FVWM_USERDIR]/preferences/ |
| 88 |
+ I TestRC (NoMatch) Test (f $[FVWM_SYSTEMDIR]/preferences/$0) Exec exec cp $[FVWM_SYSTEMDIR]/preferences/$0 $[FVWM_USERDIR]/preferences/ |
| 89 |
|
| 90 |
CopyPreferences ShowDirectories |
| 91 |
|
| 92 |
# vim:ft=fvwm |