-
Notifications
You must be signed in to change notification settings - Fork 11
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
vars1ty
committed
Jan 15, 2023
1 parent
58413e5
commit e7c8571
Showing
8 changed files
with
126 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Aliases | ||
These aliases are only valid for commands (+ tooltip commands). | ||
*** | ||
- `%username%` - Username | ||
- `%hostname%` - Hostname | ||
- `%shell%` - Active Session Shell | ||
- `%distro%` - Distribution name | ||
- `%distro_id%` - Distribution ID, for example: `arch` | ||
- `%distro_build_id%` - Distribution Build ID, for example `rolling` | ||
- `%total_mem%` - Total amount of installed memory (in GB) | ||
- `%cached_mem%` - Total amount of cached memory (in GB) | ||
- `%available_mem%` - Total amount of available memory (in GB) | ||
- `%used_mem%` - Total amount of used memory (in GB) | ||
|
||
## I can just use `whoami`, why all of this? | ||
You may use completely dynamic commands like `whoami` if you want, the benefit over aliases though are: | ||
|
||
1. Lower overhead due to being cached and retrieved via `libc`, rather than expensive commands | ||
2. A lot faster to process | ||
3. Cached at startup, then reused afterwards |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[package] | ||
name = "hybrid-bar" | ||
authors = [ "varsity <[email protected]>" ] | ||
version = "0.3.9" | ||
version = "0.4.0" | ||
edition = "2021" | ||
description = "A simple status bar made for wlroots compositors." | ||
license = "MIT" | ||
|
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,80 @@ | ||
use crate::config::SYSINFO; | ||
|
||
/// Replaces `find` with `replace` if found. | ||
fn replace_if_present(content: &mut String, find: &str, replace: &str, found_any: &mut bool) { | ||
if content.contains(find) { | ||
*content = content.replace(find, replace); | ||
*found_any = true; | ||
} | ||
} | ||
|
||
/// Checks if the `content` contains any of the built-in aliases, then replaces it with the real | ||
/// value. | ||
pub fn use_aliases(content: &str) -> String { | ||
// TODO: Clean this up. | ||
let mut found_any = false; | ||
let mut content = content.to_owned(); | ||
replace_if_present( | ||
&mut content, | ||
"%username%", | ||
&SYSINFO.username, | ||
&mut found_any, | ||
); | ||
replace_if_present( | ||
&mut content, | ||
"%hostname%", | ||
&SYSINFO.hostname, | ||
&mut found_any, | ||
); | ||
replace_if_present(&mut content, "%shell%", &SYSINFO.shell, &mut found_any); | ||
replace_if_present(&mut content, "%kernel%", &SYSINFO.kernel, &mut found_any); | ||
replace_if_present( | ||
&mut content, | ||
"%used_mem%", | ||
&SYSINFO.used_mem, | ||
&mut found_any, | ||
); | ||
replace_if_present( | ||
&mut content, | ||
"%distro_id%", | ||
&SYSINFO.distro_id, | ||
&mut found_any, | ||
); | ||
replace_if_present( | ||
&mut content, | ||
"%total_mem%", | ||
&SYSINFO.total_mem, | ||
&mut found_any, | ||
); | ||
replace_if_present( | ||
&mut content, | ||
"%cached_mem%", | ||
&SYSINFO.cached_mem, | ||
&mut found_any, | ||
); | ||
replace_if_present( | ||
&mut content, | ||
"%available_mem%", | ||
&SYSINFO.available_mem, | ||
&mut found_any, | ||
); | ||
replace_if_present( | ||
&mut content, | ||
"%distro%", | ||
&SYSINFO.distro_name, | ||
&mut found_any, | ||
); | ||
replace_if_present( | ||
&mut content, | ||
"%distro_build_id%", | ||
&SYSINFO.distro_build_id, | ||
&mut found_any, | ||
); | ||
|
||
if !found_any { | ||
// Couldn't find any aliases present, run execute. | ||
return execute!(&content); | ||
} | ||
|
||
content | ||
} |
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