Trims fat and renames files

This commit is contained in:
William Carroll 2016-08-15 11:14:37 -04:00
parent 6021ad3194
commit 4563550969
40 changed files with 233 additions and 352 deletions

View file

@ -0,0 +1,13 @@
#!/usr/bin/env bash
if [ -d /Volumes/usb_vim ] && \ # usb has mounted
[ ! -L "$HOME/.vimrc" ] && \ # .vimrc is a symlink
[ ! -L "$HOME/.vim" ]; then # .vim dir is a symlink
. "/Volumes/usb_vim/vim/vim_point_to_usb.sh"
. "$HOME/pc_settings/launchd_scripts/notice.sh"
else
. "$HOME/pc_settings/launchd_scripts/notice_2.sh"
fi

34
launchd_scripts/bootstrap.sh Executable file
View file

@ -0,0 +1,34 @@
#!/usr/bin/env bash
# Unload scripts in case there have been changes since it was last loaded.
echo -n "Unloading personal *.plist files... " &&
launchctl unload ~/Library/LaunchAgents/watch_volumes.plist &&
echo "Done." || echo "Error."
# Remove *.plist symlinks created last time.
echo -n "Removing *.plist symlinks... " &&
rm ~/Library/LaunchAgents/watch_volumes.plist &&
echo "Done." || echo "Error."
# Process the *.tpl files, replacing global identifiers with the values
# from vars.json.
echo -n "Processing *.tpl files... " &&
. ./process_files.sh &&
echo "Done." || echo "Error."
# Recreate those symlinks.
echo -n "Recreating *.plist symlinks to ~/Library/LaunchAgents ... " &&
ln -s ~/pc_settings/launchd_scripts/watch_volumes.plist \
~/Library/LaunchAgents/watch_volumes.plist &&
echo "Done." || echo "Error."
# Reload scripts in case there have been changes since it was last loaded.
echo -n "Reloading personal *.plist files... " &&
launchctl load ~/Library/LaunchAgents/watch_volumes.plist &&
echo "Done." || echo "Error."

5
launchd_scripts/notice.sh Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
osascript -e "tell Application \"System Events\" to display alert\
\"New volume mounted.\""

5
launchd_scripts/notice_2.sh Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
osascript -e "tell Application \"System Events\" to display alert\
\"Not going to switch!\""

View file

@ -0,0 +1,15 @@
#!/usr/bin/env bash
# This script processes certain files and replaces
# {{<IDENTIFIER>}} with the entries in vars.json
output_path="./watch_volumes.plist"
template_file="watch_volumes.plist.tpl"
usb_drive_path=$(jq < ./vars.json '.USB_DRIVE_PATH' | \
sed 's/\//\\\//g' | sed 's/"//g')
cat "$template_file" | perl -p -e 's/(\{\{[^}]+\}\})/'$usb_drive_path'/g' \
>"$output_path"
echo "Done."

View file

@ -0,0 +1,3 @@
{
"USB_DRIVE_PATH": "/Volumes/usb_vim/"
}

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>WatchVolumes</string>
<key>ProgramArguments</key>
<array>
<string>/Users/wcarroll/pc_settings/launchd_scripts/attempt_vim_switch.sh</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Volumes/usb_vim/</string>
</array>
</dict>
</plist>

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>WatchVolumes</string>
<key>ProgramArguments</key>
<array>
<string>/Users/wcarroll/pc_settings/launchd_scripts/attempt_vim_switch.sh</string>
</array>
<key>WatchPaths</key>
<array>
<string>{{USB_DRIVE_PATH}}</string>
</array>
</dict>
</plist>