-
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.
Support for tmux >= 2.9, with window-size
- Loading branch information
Philipp Heckel
committed
Oct 3, 2021
1 parent
73111d7
commit 7499e46
Showing
3 changed files
with
74 additions
and
44 deletions.
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
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,49 @@ | ||
package util | ||
|
||
import ( | ||
_ "embed" // required by go:embed | ||
"errors" | ||
"fmt" | ||
"os/exec" | ||
"regexp" | ||
"strconv" | ||
) | ||
|
||
const ( | ||
minimumTmuxVersion = 2.6 // see issue #39 | ||
windowSizeTmuxVersion = 2.9 // see issue #44 | ||
) | ||
|
||
var ( | ||
tmuxVersionRegex = regexp.MustCompile(`tmux (\d+\.\d+)`) | ||
) | ||
|
||
// CheckTmuxVersion checks the version of tmux and returns an error if it's not supported | ||
func CheckTmuxVersion() error { | ||
return checkTmuxVersion(minimumTmuxVersion) | ||
} | ||
|
||
// supportsTmuxWindowSize checks if the "window-size" option is supported (tmux >= 2.9) | ||
func supportsTmuxWindowSize() bool { | ||
return checkTmuxVersion(windowSizeTmuxVersion) == nil | ||
} | ||
|
||
func checkTmuxVersion(compareVersion float64) error { | ||
cmd := exec.Command("tmux", "-V") | ||
output, err := cmd.CombinedOutput() | ||
if err != nil { | ||
return err | ||
} | ||
matches := tmuxVersionRegex.FindStringSubmatch(string(output)) | ||
if len(matches) <= 1 { | ||
return errors.New("unexpected tmux version output") | ||
} | ||
version, err := strconv.ParseFloat(matches[1], 32) | ||
if err != nil { | ||
return err | ||
} | ||
if version < compareVersion-0.01 { // floats are fun | ||
return fmt.Errorf("tmux version too low: tmux %.1f required, but found tmux %.1f", compareVersion, version) | ||
} | ||
return nil | ||
} |