Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
ximperconf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ximper Linux
ximperconf
Commits
762c7f44
Verified
Commit
762c7f44
authored
Feb 16, 2026
by
Kirill Unitsaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
preset: add show command and profile-level if-exec condition
parent
725ccfc3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
194 additions
and
33 deletions
+194
-33
presets.go
config/presets.go
+34
-33
actions.go
preset/actions.go
+145
-0
commands.go
preset/commands.go
+8
-0
helpers.go
preset/helpers.go
+7
-0
No files found.
config/presets.go
View file @
762c7f44
...
...
@@ -10,63 +10,64 @@ import (
)
type
CopyEntry
struct
{
Src
string
`yaml:"src"`
Dest
string
`yaml:"dest"`
Src
string
`yaml:"src"
json:"src"
`
Dest
string
`yaml:"dest"
json:"dest"
`
}
type
LinkEntry
struct
{
Src
string
`yaml:"src"`
Dest
string
`yaml:"dest"`
Apps
[]
string
`yaml:"apps,omitempty"`
Src
string
`yaml:"src"
json:"src"
`
Dest
string
`yaml:"dest"
json:"dest"
`
Apps
[]
string
`yaml:"apps,omitempty"
json:"apps,omitempty"
`
}
type
ReplaceEntry
struct
{
Src
string
`yaml:"src"`
Dest
string
`yaml:"dest"`
Src
string
`yaml:"src"
json:"src"
`
Dest
string
`yaml:"dest"
json:"dest"
`
}
type
GrubEntry
struct
{
FixResolution
bool
`yaml:"fix-resolution,omitempty"`
Update
bool
`yaml:"update,omitempty"`
FixResolution
bool
`yaml:"fix-resolution,omitempty"
json:"fix_resolution,omitempty"
`
Update
bool
`yaml:"update,omitempty"
json:"update,omitempty"
`
}
type
SystemEntry
struct
{
Grub
GrubEntry
`yaml:"grub,omitempty"`
Grub
GrubEntry
`yaml:"grub,omitempty"
json:"grub,omitempty"
`
}
type
HyprVar
struct
{
Name
string
`yaml:"name"`
Value
string
`yaml:"value"`
Force
bool
`yaml:"force,omitempty"`
Name
string
`yaml:"name"
json:"name"
`
Value
string
`yaml:"value"
json:"value"
`
Force
bool
`yaml:"force,omitempty"
json:"force,omitempty"
`
}
type
HyprModule
struct
{
Name
string
`yaml:"name"`
Action
string
`yaml:"action"`
User
bool
`yaml:"user,omitempty"`
NewOnly
bool
`yaml:"new-only,omitempty"`
IfExec
string
`yaml:"if-exec,omitempty"`
IfBinary
string
`yaml:"if-binary,omitempty"`
Init
bool
`yaml:"init,omitempty"`
Name
string
`yaml:"name"
json:"name"
`
Action
string
`yaml:"action"
json:"action"
`
User
bool
`yaml:"user,omitempty"
json:"user,omitempty"
`
NewOnly
bool
`yaml:"new-only,omitempty"
json:"new_only,omitempty"
`
IfExec
string
`yaml:"if-exec,omitempty"
json:"if_exec,omitempty"
`
IfBinary
string
`yaml:"if-binary,omitempty"
json:"if_binary,omitempty"
`
Init
bool
`yaml:"init,omitempty"
json:"init,omitempty"
`
}
type
HyprlandEntry
struct
{
SyncLayouts
bool
`yaml:"sync-layouts,omitempty"`
Check
bool
`yaml:"check,omitempty"`
Vars
[]
HyprVar
`yaml:"vars,omitempty"`
Modules
[]
HyprModule
`yaml:"modules,omitempty"`
SyncLayouts
bool
`yaml:"sync-layouts,omitempty"
json:"sync_layouts,omitempty"
`
Check
bool
`yaml:"check,omitempty"
json:"check,omitempty"
`
Vars
[]
HyprVar
`yaml:"vars,omitempty"
json:"vars,omitempty"
`
Modules
[]
HyprModule
`yaml:"modules,omitempty"
json:"modules,omitempty"
`
}
type
PresetProfile
struct
{
Binary
string
`yaml:"binary,omitempty"`
Description
string
`yaml:"description,omitempty"`
Root
bool
`yaml:"root,omitempty"`
Priority
int
`yaml:"priority,omitempty"`
Copy
[]
CopyEntry
`yaml:"copy,omitempty"`
Links
[]
LinkEntry
`yaml:"links,omitempty"`
Replace
[]
ReplaceEntry
`yaml:"replace,omitempty"`
System
SystemEntry
`yaml:"system,omitempty"`
Hyprland
HyprlandEntry
`yaml:"hyprland,omitempty"`
Binary
string
`yaml:"binary,omitempty" json:"binary,omitempty"`
Description
string
`yaml:"description,omitempty" json:"description,omitempty"`
Root
bool
`yaml:"root,omitempty" json:"root,omitempty"`
Priority
int
`yaml:"priority,omitempty" json:"priority,omitempty"`
IfExec
string
`yaml:"if-exec,omitempty" json:"if_exec,omitempty"`
Copy
[]
CopyEntry
`yaml:"copy,omitempty" json:"copy,omitempty"`
Links
[]
LinkEntry
`yaml:"links,omitempty" json:"links,omitempty"`
Replace
[]
ReplaceEntry
`yaml:"replace,omitempty" json:"replace,omitempty"`
System
SystemEntry
`yaml:"system,omitempty" json:"system,omitempty"`
Hyprland
HyprlandEntry
`yaml:"hyprland,omitempty" json:"hyprland,omitempty"`
}
func
loadPresetProfiles
(
dir
string
)
(
map
[
string
]
PresetProfile
,
error
)
{
...
...
preset/actions.go
View file @
762c7f44
...
...
@@ -14,6 +14,7 @@ import (
"ximperconf/hyprland"
"ximperconf/locale"
"ximperconf/system"
"ximperconf/ui"
"github.com/fatih/color"
"github.com/urfave/cli/v3"
...
...
@@ -440,3 +441,147 @@ func presetInfoCommand(ctx context.Context, cmd *cli.Command) error {
ShowProfilesInfo
(
config
.
IsJSON
(
cmd
))
return
nil
}
type
profileShowJSON
struct
{
Name
string
`json:"name"`
Status
string
`json:"status"`
config
.
PresetProfile
}
func
presetShowCommand
(
ctx
context
.
Context
,
cmd
*
cli
.
Command
)
error
{
name
:=
cmd
.
Args
()
.
Get
(
0
)
if
name
==
""
{
ShowProfilesInfo
(
config
.
IsJSON
(
cmd
))
return
nil
}
prof
,
ok
:=
config
.
Env
.
Profiles
[
name
]
if
!
ok
{
color
.
Red
(
locale
.
T
(
"Profile %s not found"
),
name
)
return
nil
}
status
:=
profileStatus
(
prof
)
if
config
.
IsJSON
(
cmd
)
{
return
ui
.
PrintJSON
(
profileShowJSON
{
Name
:
name
,
Status
:
status
.
Label
,
PresetProfile
:
prof
,
})
}
header
:=
status
.
Color
(
"%s %s"
,
status
.
Symbol
,
name
)
if
prof
.
Description
!=
""
{
fmt
.
Printf
(
"%s — %s
\n
"
,
header
,
prof
.
Description
)
}
else
{
fmt
.
Println
(
header
)
}
blue
:=
color
.
New
(
color
.
FgBlue
)
.
SprintFunc
()
if
prof
.
Binary
!=
""
{
fmt
.
Printf
(
" %s: %s
\n
"
,
blue
(
"binary"
),
prof
.
Binary
)
}
if
prof
.
Priority
!=
0
{
fmt
.
Printf
(
" %s: %d
\n
"
,
blue
(
"priority"
),
prof
.
Priority
)
}
if
prof
.
Root
{
fmt
.
Printf
(
" %s: %s
\n
"
,
blue
(
"root"
),
locale
.
T
(
"yes"
))
}
if
prof
.
IfExec
!=
""
{
fmt
.
Printf
(
" %s: %s
\n
"
,
blue
(
"if-exec"
),
prof
.
IfExec
)
}
// copy
if
len
(
prof
.
Copy
)
>
0
{
fmt
.
Printf
(
"
\n
%s (%d):
\n
"
,
blue
(
locale
.
T
(
"copy"
)),
len
(
prof
.
Copy
))
for
_
,
c
:=
range
prof
.
Copy
{
fmt
.
Printf
(
" %s -> %s
\n
"
,
c
.
Src
,
c
.
Dest
)
}
}
// links
if
len
(
prof
.
Links
)
>
0
{
fmt
.
Printf
(
"
\n
%s (%d):
\n
"
,
blue
(
locale
.
T
(
"link"
)),
len
(
prof
.
Links
))
for
_
,
l
:=
range
prof
.
Links
{
s
:=
l
.
Src
+
" -> "
+
l
.
Dest
if
len
(
l
.
Apps
)
>
0
{
s
+=
" ["
+
strings
.
Join
(
l
.
Apps
,
", "
)
+
"]"
}
fmt
.
Printf
(
" %s
\n
"
,
s
)
}
}
// replace
if
len
(
prof
.
Replace
)
>
0
{
fmt
.
Printf
(
"
\n
%s (%d):
\n
"
,
blue
(
locale
.
T
(
"replace"
)),
len
(
prof
.
Replace
))
for
_
,
r
:=
range
prof
.
Replace
{
fmt
.
Printf
(
" %s -> %s
\n
"
,
r
.
Src
,
r
.
Dest
)
}
}
// system
if
prof
.
System
.
Grub
.
FixResolution
{
fmt
.
Printf
(
"
\n
%s:
\n
"
,
blue
(
locale
.
T
(
"system"
)))
fmt
.
Println
(
" grub:"
)
fmt
.
Printf
(
" fix-resolution: %v
\n
"
,
prof
.
System
.
Grub
.
FixResolution
)
if
prof
.
System
.
Grub
.
Update
{
fmt
.
Printf
(
" update: %v
\n
"
,
prof
.
System
.
Grub
.
Update
)
}
}
// hyprland
hasHypr
:=
len
(
prof
.
Hyprland
.
Modules
)
>
0
||
len
(
prof
.
Hyprland
.
Vars
)
>
0
||
prof
.
Hyprland
.
SyncLayouts
||
prof
.
Hyprland
.
Check
if
hasHypr
{
fmt
.
Printf
(
"
\n
%s:
\n
"
,
blue
(
"hyprland"
))
if
prof
.
Hyprland
.
SyncLayouts
{
fmt
.
Printf
(
" sync-layouts: %s
\n
"
,
locale
.
T
(
"yes"
))
}
if
prof
.
Hyprland
.
Check
{
fmt
.
Printf
(
" check: %s
\n
"
,
locale
.
T
(
"yes"
))
}
if
len
(
prof
.
Hyprland
.
Modules
)
>
0
{
fmt
.
Printf
(
" %s (%d):
\n
"
,
blue
(
locale
.
T
(
"module"
)),
len
(
prof
.
Hyprland
.
Modules
))
for
_
,
m
:=
range
prof
.
Hyprland
.
Modules
{
s
:=
m
.
Name
+
": "
+
m
.
Action
var
flags
[]
string
if
m
.
User
{
flags
=
append
(
flags
,
"user"
)
}
if
m
.
NewOnly
{
flags
=
append
(
flags
,
"new-only"
)
}
if
m
.
Init
{
flags
=
append
(
flags
,
"init"
)
}
if
len
(
flags
)
>
0
{
s
+=
" ("
+
strings
.
Join
(
flags
,
", "
)
+
")"
}
fmt
.
Printf
(
" %s
\n
"
,
s
)
if
m
.
IfBinary
!=
""
{
fmt
.
Printf
(
" if-binary: %s
\n
"
,
m
.
IfBinary
)
}
if
m
.
IfExec
!=
""
{
fmt
.
Printf
(
" if-exec: %s
\n
"
,
m
.
IfExec
)
}
}
}
if
len
(
prof
.
Hyprland
.
Vars
)
>
0
{
fmt
.
Printf
(
" %s (%d):
\n
"
,
blue
(
locale
.
T
(
"var"
)),
len
(
prof
.
Hyprland
.
Vars
))
for
_
,
v
:=
range
prof
.
Hyprland
.
Vars
{
s
:=
v
.
Name
+
" = "
+
v
.
Value
if
v
.
Force
{
s
+=
" (force)"
}
fmt
.
Printf
(
" %s
\n
"
,
s
)
}
}
}
return
nil
}
preset/commands.go
View file @
762c7f44
...
...
@@ -34,6 +34,14 @@ func CommandList() *cli.Command {
Action
:
presetInfoCommand
,
},
{
Name
:
"show"
,
Usage
:
locale
.
T
(
"Show profile details"
),
ArgsUsage
:
"profile"
,
Flags
:
[]
cli
.
Flag
{
config
.
FormatFlag
},
Action
:
presetShowCommand
,
ShellComplete
:
ShellCompleteProfiles
,
},
{
Name
:
"apply"
,
Usage
:
locale
.
T
(
"Apply a profile"
),
Flags
:
presetFlags
,
...
...
preset/helpers.go
View file @
762c7f44
...
...
@@ -25,6 +25,13 @@ func profileAvailable(p config.PresetProfile) bool {
return
false
}
if
p
.
IfExec
!=
""
{
out
,
err
:=
exec
.
Command
(
"sh"
,
"-c"
,
p
.
IfExec
)
.
Output
()
if
err
!=
nil
||
len
(
strings
.
TrimSpace
(
string
(
out
)))
==
0
{
return
false
}
}
return
true
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment