图标的这个问题困扰了我一段时间。基本的解决方案基本上是完全忽略文件,我拒绝这样做,因为我是一个视觉人,喜欢浪费我的时间为我的项目创建很酷的图标。
注意:我已尽力确保它有效,但我无法保证,因此请尝试复制您的数据。话虽如此,这里是我对这个问题的解决方案。
基本上我创建了 3 个脚本来解决 mac icon\r 问题。
- repoMacPrepare.sh
- repoMacRestore.sh
- gitAliasScript.sh
这三个脚本用于添加 git 或 svn 可以接受和存储的格式的 mac 图标。第一个脚本准备存储库,搜索目录中基于图标的文件和文件中的自定义图标格式。然后将它们作为 .jdIcnd 或 .jdIcnf(d 表示目录 f 表示文件夹)存储在各自的路径中。
第二个脚本允许它通过搜索 .jdIcnd 和 .jdIcnf 文件在 Mac 上恢复活力。
最后一个脚本显示了如何自动化该过程。我为 git 使用了一个别名,它引用了我的 .bashrc 文件中的 gitAliasScript.sh 脚本。现在我切换到 git(我做的最好的事情),所以脚本显示为 git,但基本在 svn 中是相同的。我希望这可以帮助使用版本控制系统的 Mac 用户在签入过程或签出过程中不会丢失图标。另请注意,那些不使用此脚本的人不会有问题,因为图标存储为带有点前缀的二进制文件,使它们不可见。哦对了……
文件:repoMacPrepare.sh
#! /bin/bash
#
# Author: Joshua Demori
# Email: jdemori@jrdfamily.com
#
# This script is used to prepare a repository
# to still record the Icons used on a mac for files or directories
#
# First
# DeRez Icon^M > .IconCntrlR
# (hit control-v then enter to get the carriage return vi)
#
# Store in Repository
# then to bring back
# Rez -append IconCopy -o Icon
# # may need to set the Folders Icon Info
# SetFile -a C /Path/To/Custom/Folder/With/Icon/
#
# if I need to SetFile the folder I can do this 2 ways
# a main file which has all this data at base of repository (bad)
# as it finds those files it does the folder below it
#
#
#=======================================================#
# Defines
readonly VERSION=1.00
#=======================================================#
# Variables
varVerbose=false
#=======================================================#
# Functions
setupDirIcon () {
DeRez "${file}"/Icon
> "${file}"/.Icon.jdIcnd
if [ $varVerbose == true ]; then
echo Adding Icon File: "$file"/.Icon.jdIcnd
fi
}
setupFileIcon () {
base=`basename "$file"`
path=`dirname "$file"`
DeRez "$file" > "${path}"/."${base}".jdIcnf
if [ $varVerbose == true ]; then
echo Adding Icon File: "$file"/."${base}".jdIcnf
fi
}
# cmd line functions
function funcOptionVersion {
echo "Reposiotry Mac Icon Preperation Script Version: $VERSION"
exit 0
}
function funcOptionHelp {
name=`basename $0`
echo $name Help Screen
echo '-h help'
echo '-v verbose'
echo '-n version'
echo ' '
exit 0
}
function funcOptionVerbose {
varVerbose=true
}
#=======================================================#
# process cmd line arguments
while getopts "vhn" optionName; do
case "$optionName" in
n) funcOptionVersion ;;
h) funcOptionHelp ;;
v) funcOptionVerbose ;;
[?]) printErrorHelpAndExit "$badOptionHelp";;
esac
done
#=======================================================#
#=======================================================#
# Start main portion of script
# ignore . .DS_Store .git folders and files
find . | grep -v ^.$ | grep -v .DS_Store | grep -v .git | grep -v .svn | while read file
do
# does this file have an icon attribute
GetFileInfo -a "$file" | grep C > /dev/null
if [ $? = 0 ]; then
if [ -d "$file" ]; then
setupDirIcon
else
setupFileIcon
fi
fi # end if for icon test
done
# Remove Only the Icon file used by directories
echo Removing Icon File
if [ $varVerbose == true ]; then
find . -name Icon
-print -exec rm {} \;
else
find . -name Icon
-exec rm {} \;
fi
文件:repoMacRestore.sh
#! /bin/bash
#
# Author: Joshua Demori
# Email: jdemori@jrdfamily.com
#
# This Script complemnts xxxx by reversing the icons as derez to rez
# then setting the proper file attributes to view the icons
#
# First
# DeRez Icon^M > .IconCntrlR
# (hit control-v then enter to get the carriage return vi)
#
# Store in Repository
# then to bring back
# Rez -append IconCopy -o Icon
# # may need to set the Folders Icon Info
# SetFile -a C /Path/To/Custom/Folder/With/Icon/
#
# if I need to SetFile the folder I can do this 2 ways
# a main file which has all this data at base of repository (bad)
# as it finds those files it does the folder below it
#
#
#=======================================================#
# Defines
readonly VERSION=1.00
#=======================================================#
# Variables
varVerbose=false
#=======================================================#
# Functions
# cmd line functions
function funcOptionVersion {
echo "Repository Mac Icon Restore Script Version: $VERSION"
exit 0
}
function funcOptionHelp {
name=`basename $0`
echo $name Help Screen
echo '-h help'
echo '-v verbose'
echo '-n version'
echo ' '
exit 0
}
function funcOptionVerbose {
varVerbose=true
}
#=======================================================#
# process cmd line arguments
while getopts "vhn" optionName; do
case "$optionName" in
n) funcOptionVersion ;;
h) funcOptionHelp ;;
v) funcOptionVerbose ;;
[?]) printErrorHelpAndExit "$badOptionHelp";;
esac
done
#=======================================================#
#=======================================================#
# Start main portion of script
#=======================================================#
# Go thourgh directories
find . -name *.jdIcnd | while read file
do
# is it a dir - restore dir icon
echo "$file" | grep jdIcnd
if [ $? = 0 ]; then
if [ $varVerbose == true ]; then
echo Fixing Directory Icon: "$file"
fi
path=`dirname "$file"`
Rez "$file" -o "${path}"/Icon
SetFile -a V "${path}"/Icon
SetFile -a C "${path}"
fi
done
# Go thourgh files
# is it a file - restore file icon
find . -name *.jdIcnf | while read file
do
echo "$file" | grep jdIcnf
if [ $? = 0 ]; then
path=`dirname "$file"`
base=`basename "$file"`
origFileName=`echo "$base" | sed 's/\.jdIcnf//'`
origFileName=`echo "${origFileName:1}"`
fileWithPath="${path}"/"${origFileName}"
if [ $varVerbose == true ]; then
echo Restoring File Icon: "$path"
fi
#echo origFileName: "$origFileName"
#echo filesWithPath: "$fileWithPath"
Rez -append "$file" -o "$fileWithPath"
SetFile -a C "$fileWithPath"
fi
done
gitAliasScript.sh
#! /bin/bash
found=false
args=("$@")
for var in "$@"
do
x=`echo $var | grep -ic commit`
if [ $x == 1 ]; then
# prepare icons to be saved
# add them to repository
# at the end git is run
repoMacPrepare.sh
find . -name *.jdIcnd -exec git add {} \;
find . -name *.jdIcnf -exec git add {} \;
found=true
fi
done
#runs git cmd here
cmdPart='git '
cmd=${cmdPart}${@}
$cmd
# finish by bringing back icons
# if commit was called
if [ $found == true ]; then
repoMacRestore.sh
fi
exit 0