把Ubuntu的使用者目錄改回英文的script

每次安裝完新的Ubuntu都有一個很惱人的問題。那就是使用者的目錄是中文的。command line用習慣的人,都知道打命令的時候輸入中文是一件很討厭的事情。所以,弄了下面這個script來將目錄名稱換回英文的。

#!/bin/sh
# This shell script utilizes xdg-user-dir and xdg-user-dirs-update to
# change all user dirs back to original name in English.
USER_FOLDERS="DESKTOP DOWNLOAD TEMPLATES PUBLICSHARE DOCUMENTS MUSIC PICTURES VIDEOS"
USER_HOME=`xdg-user-dir`
for USER_FOLDER in $USER_FOLDERS; do
    FOLDER_ABSNAME=`xdg-user-dir $USER_FOLDER`
    FOLDER_DIRNAME=`dirname $FOLDER_ABSNAME`
    FOLDER_BASENAME=`basename $FOLDER_ABSNAME`
    FOLDER_TARGET="$FOLDER_DIRNAME/$USER_FOLDER"
    if [ "$FOLDER_ABSNAME" = "$USER_HOME" ]; then
        # Ignore invalid folder.
        echo WARNING: $USER_FOLDER is invalid.
        continue
    fi
    if [ "$FOLDER_TARGET" = "$FOLDER_ABSNAME" ]; then
        # Ignore the folder which has been matched to target name.
        continue
    fi
    # Uncomment following lines for debugging purpose.
    #echo $USER_FOLDER $FOLDER_ABSNAME "(" $FOLDER_DIRNAME "," $FOLDER_BASENAME ")"
    # Update user dir.
    xdg-user-dirs-update --force --set $USER_FOLDER "$FOLDER_DIRNAME/$USER_FOLDER"
    # Move corresponding folder to new place.
    mv "$FOLDER_ABSNAME" "$FOLDER_DIRNAME/$USER_FOLDER"
done
comments powered by Disqus