-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c215c8
commit 3a01146
Showing
4 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/zsh | ||
set -xeu | ||
|
||
user="$1" | ||
remove_user_data="$2" | ||
APP_DIR="/Library/Input Methods/Fcitx5.app" | ||
DATA_DIR="/Users/$user/Library/fcitx5" | ||
CONFIG_DIR="/Users/$user/.config/fcitx5" | ||
LOCAL_DIR="/Users/$user/.local/share/fcitx5" | ||
|
||
rm -rf "$APP_DIR" | ||
rm -rf "$DATA_DIR" | ||
rm -rf "$CONFIG_DIR" | ||
|
||
if [ "$remove_user_data" = "true" ]; then | ||
rm -rf "$LOCAL_DIR" | ||
fi | ||
|
||
killall Fcitx5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Foundation | ||
import Logging | ||
|
||
func quote(_ s: String) -> String { | ||
return s.replacingOccurrences(of: "\\", with: "\\\\").replacingOccurrences(of: "\"", with: "\\\"") | ||
} | ||
|
||
func twiceQuote(_ s: String) -> String { | ||
let quoted = quote(s) | ||
return quote("\"\(quoted)\"") | ||
} | ||
|
||
func sudo(_ script: String, _ arg: String, _ logPath: String) -> Bool { | ||
let user = NSUserName() | ||
guard let scriptPath = Bundle.main.path(forResource: script, ofType: "sh") else { | ||
FCITX_ERROR("\(script).sh not found") | ||
return false | ||
} | ||
let command = | ||
"do shell script \"\(twiceQuote(scriptPath)) \(twiceQuote(user)) \(twiceQuote(arg)) 2>\(logPath)\" with administrator privileges" | ||
guard let appleScript = NSAppleScript(source: command) else { | ||
FCITX_ERROR("Fail to initialize AppleScript") | ||
return false | ||
} | ||
var error: NSDictionary? = nil | ||
appleScript.executeAndReturnError(&error) | ||
if let error = error { | ||
FCITX_ERROR("Fail to execute AppleScript: \(error)") | ||
return false | ||
} | ||
return true | ||
} |