What I'm trying to do
I'm automating my git work with Sublime Merge.
Luckily, that software puts the whole path to the git repo in the win title.
So I can parse it and run some git commands.
One Hotkey runs
Code: Select all
git status -s
The Code
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Source
; https://www.autohotkey.com/docs/commands/Run.htm#StdOut
RunWaitOne(command, workingDir="") {
; WshShell object: http://msdn.microsoft.com/en-us/library/aew9yb99
shell := ComObjCreate("WScript.Shell")
if(workingDir != ""){
; gets the original CurrentDirectory and
; sets the new one
originalCurrDir := shell.CurrentDirectory
shell.CurrentDirectory := workingDir
}
; Execute a single command via cmd.exe
exec := shell.Exec(ComSpec " /C" command)
; Read and return the command's output
if(workingDir != ""){
; reset the original current directory otherwise
; the %WorkingDir% for the current AHK process would
; also change!
shell.CurrentDirectory := originalCurrDir
}
readAll := exec.StdOut.ReadAll()
out := []
Loop, Parse, readAll, `n
{
out.Push( A_loopField )
}
return ArrayJoin(out, "`n")
}
;https://www.autohotkey.com/boards/viewtopic.php?t=7124
ArrayJoin(arr, separator:=",", printIndex:=False){
str := ""
for index,el in arr {
if(printIndex){
str .= "[" . index . "]"
}
str .= el . separator
}
return SubStr(str, 1, -StrLen(separator))
}
; result := RunWaitOne("dir /B", A_WorkingDir)
result := RunWaitOne("git status -s", A_WorkingDir)
MsgBox, % result
My repositories are in portuguese, spanish, french, etc and I want to be able to deal with all kinds of characters, but a lot of them are appearing as
Code: Select all
\303\[3 digits]
My AHK installation is UNICODE, btw.
What I've tried
I've tried a lot of different things, including looping through the lines and using StrReplace like:
Code: Select all
StrReplace(A_LoopField, "\303\243", "ã")
Tried StrGet/StrPut.
I feel I'm missing something very simple.
How to test
I've attached a zip file containing a MVE repository. You just need to execute the .ahk script on it. Of course, you need git on your PATH