     ;vifm - activate/run
     #e::
     {
-        IfWinExist, ahk_class Vifm
-        {
-            WinShow
-            WinActivate
-        }
-        else
-        {
-            Run, %CygPath%\bin\mintty.exe --window max --class "Vifm" --exec /bin/zsh -l -i -c vifm, %CygPath%/bin
-            WinWait, ahk_class Vifm
+        If WinExist("ahk_class Vifm") {
+            WinShow
+            WinActivate
+        } else {
+            Run(CygPath . "\\bin\\mintty.exe --window max --class Vifm --exec /bin/zsh -l -i -c vifm", CygPath . "/bin")
+            WinWait("ahk_class Vifm")
         }
         return
     }


#Persistent
#SingleInstance Force
DetectHiddenWindows, On
DetectHiddenText, On
SetTitleMatchMode, RegEx ;match titles and classes using regular expressions
SetTitleMatchMode Slow ;match titles and classes using regular expressions
CoordMode, Mouse, Screen
CoordMode, ToolTip, Screen

;detect cygwin
global CygPath
CygPath = C:\Program Files (x86)\cygwin
IfNotExist %CygPath%
    CygPath = C:\Cygwin
IfNotExist %CygPath%
    CygPath = C:\Cygwin64

;detect browser
global BrowserPath
BrowserPath = C:\Program Files (x86)\Mozilla Firefox\firefox.exe
IfNotExist %BrowserPath%
    BrowserPath = "C:\Users\rr-\AppData\Local\Google\Chrome\Application\chrome.exe"

;disable windows+l
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 1

;activate/run a program
FRun(window, path, folder)
{
    if (!window or !WinExist(window))
    {
        Run, %path%, %folder%
    }
    else
    {
        WinShow
        WinActivate
    }
    return
}

return

;replace stuff in clipboard when it changes
OnClipboardChange:
{
    if (A_EventInfo == 1) and (SubStr(clipboard, 1, 7) == "http://")
    {
        StringReplace, clipboard, clipboard, [, `%5b, All
        StringReplace, clipboard, clipboard, \, `%5c, All
        StringReplace, clipboard, clipboard, ], `%5d, All
    }
    return
}

#If FileExist(CygPath)
    ;cygwin - activate/run
    #Enter::
    {
        Run, %CygPath%\bin\mintty.exe --title "Terminal" --class "mintty_thetty" --exec /bin/zsh -i -l, %CygPath%
        return
    }
    +^![::
    {
        Run, %CygPath%\bin\mintty.exe --title "Terminal" --class "mintty_thetty" --exec /bin/zsh -i -l, %CygPath%
        return
    }
    ^![::
    {
        if (!WinExist("ahk_class mintty_thetty"))
        {
            Run, %CygPath%\bin\mintty.exe --title "Terminal" --class "mintty_thetty" --exec /bin/zsh -i -l, %CygPath%
            WinWait ahk_class mintty_thetty
        }
        else
        {
            WinShow
            WinActivate
        }

+#z::AddTransparency(12)

;music
#x::Volume_Up
+#x::Volume_Down
#c::Media_Next
+#c::Media_Prev
#v::Media_Play_Pause

;screenshots
+#i::Run(CygPath . "\\bin\\zsh.exe -i -l -c 'shot -w -i --output=Z:/'", , Hide)
#i::Run(CygPath . "\\bin\\zsh.exe -i -l -c 'shot -i --output=Z:/'", , Hide)

;reload autohotkey
!F12::Reload

;linux-compatible useful keys
RAlt & -::Send(GetKeyState("Shift") ? "{U+2014}" : "{U+2013}")
RAlt & k::Send("{U+2026}")

;hepburn macrons
RAlt & =::
{
    key := Input("L1", "{delete}{esc}{home}{end}") ; pressing any of these will terminate the input
    if key == "A" {
        Send("{U+0100}")
    } else if key == "I" {
        Send("{U+012A}")
    } else if key == "U" {
        Send("{U+016A}")
    } else if key == "E" {
        Send("{U+0112}")
    } else if key == "O" {
        Send("{U+014C}")
    } else if key == "a" {
        Send("{U+0101}")
    } else if key == "i" {
        Send("{U+012B}")
    } else if key == "u" {
        Send("{U+016B}")
    } else if key == "e" {
        Send("{U+0113}")
    } else if key == "o" {
        Send("{U+014D}")
    }
     return
}


#n::
{
    Locale1 := 0x4150415
    Locale2 := 0x4110411
    WinID := WinGetID("A")
    ThreadID := DllCall("GetWindowThreadProcessId", "Int", WinID, "Int", "0")
    InputLocaleID := DllCall("GetKeyboardLayout", "Int", ThreadID)
    if InputLocaleID == Locale1 {
        SendMessage(0x50, 0, Locale2, "", "A")
    } else if InputLocaleID == Locale2 {
        SendMessage(0x50, 0, Locale1, "", "A")
    }
}
