Skip to content

Commit

Permalink
Merge pull request #134 from yuki-was-taken/crossplatform
Browse files Browse the repository at this point in the history
Fully add MacOS and BSD support.
  • Loading branch information
iinsertNameHere authored Aug 10, 2024
2 parents 6ee08a5 + 4ae086f commit d0e5d55
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 7 deletions.
1 change: 1 addition & 0 deletions config.nims
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ proc compile(release: bool) =
args.add(&"--verbosity:0")
args.add(&"-d:danger")
args.add(&"--opt:speed")
args.add(&"-d:strip")
args.add(&"--outdir:{thisDir()}/bin")
args.add(&"{thisDir()}/src/catnap.nim")

Expand Down
9 changes: 5 additions & 4 deletions config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ uptime = {icon = " ", name = "uptime", color = "(BE)"}
distro = {icon = "", name = "distro", color = "(GN)"}
kernel = {icon = "", name = "kernel", color = "(MA)"}
desktop = {icon = "", name = "desktop", color = "(CN)"}
# terminal = {icon = " ", name = "term", color = "(RD)"}
# shell = {icon = " ", name = "shell", color = "(MA)"}
terminal = {icon = "", name = "term", color = "(RD)"}
shell = {icon = "", name = "shell", color = "(MA)"}
# packages = {icon = " ", name = "packages", color = "(RD)"} # WARNING: Resource Intensive
# weather = {icon = " ", name = "weather", color = "(BE)"} # Requires curl and an emoji font. | WARNING: Resource Intensive
# The following stats do not work on MacOS and the BSDs.
# gpu = {icon = "󱔐 ", name = "gpu", color = "(MA)"} # WARNING: Resource Intensive
# cpu = {icon = " ", name = "cpu", color = "(RD)"}
# disk_0 = {icon = " ", name = "disk", color = "(GN)"}
memory = {icon = "", name = "memory", color = "(YW)"}
# memory = {icon = " ", name = "memory", color = "(YW)"}
# battery = {icon = " ", name = "battery", color = "(GN)"}
# weather = {icon = " ", name = "weather", color = "(BE)"} # Requires curl and an emoji font. | WARNING: Resource Intensive
sep_color = "SEPARATOR"
colors = {icon = "", name = "colors", color = "!DT!", symbol = ""}

Expand Down
62 changes: 61 additions & 1 deletion config/distros.toml
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,22 @@ art = [
"@@@@#=: ",
]

[dragonfly]
alias = "dragonflybsd"
margin = [2, 3, 2,]
art = [
" ,{RD}_{WE}, ",
"('-_{RD}|{WE}_-') ",
" >--{RD}|{WE}--< ",
"(_-'{RD}|{WE}'-_) ",
" {RD}| ",
" {RD}| ",
" {RD}| ",
]

### E ###
[elementary]
alias = "elementaryos"
alias = "elementaryos"
margin = [2, 2, 3,]
art = [
"{WE} _______ ",
Expand Down Expand Up @@ -293,6 +306,17 @@ art = [

]

[freebsd]
margin = [2, 4, 2,]
art = [
"{RD}/\\,-'''''-,/\\ ",
"{RD}\\_) (_/ ",
"{RD}| | ",
"{RD}| | ",
" {RD}; ; ",
" {RD}'-_____-' ",
]

### G ###
[garuda]
margin = [3, 2, 3,]
Expand Down Expand Up @@ -416,6 +440,18 @@ art = [


### M ###
[macos]
margin = [2, 4, 2,]
art = [
"{GN} .:' ",
"{GN} _ :'_ ",
"{YW} .'\\`_\\`-'_\\`. ",
"{RD}:________.-' ",
"{RD}:________: ",
"{MA} :_______\\`-; ",
"{BE} \\`._.-._.' ",
]

[mageria]
margin = [2, 4, 3,]
art = [
Expand Down Expand Up @@ -466,6 +502,18 @@ art = [


### N ###
[netbsd]
margin = [2, 2, 2,]
art = [
"{WE}\\\\{YW}\\`-______,----__ ",
"{WE} \\\\ {YW}__,---\\`_",
"{WE} \\\\ {YW}\\`.____ ",
"{WE} \\\\{YW}-______,----\\`-",
"{WE} \\\\ ",
"{WE} \\\\ ",
"{WE} \\\\ ",
]

[nobara]
margin = [2, 2, 2,]
art = [
Expand Down Expand Up @@ -500,6 +548,18 @@ art = [
]

### O ###
[openbsd]
margin = [2, 2, 3,]
art = [
"{YW} _____ ",
"{YW} \\- -/ ",
"{YW} \\_/ \\ ",
"{YW} | {WE}O O{YW} |",
"{YW} |_ < ) 3 )",
"{YW} / \\ / ",
" {YW} /-_____-\\ ",
]

[opensuse]
margin = [0, 0, 2,]
art = [
Expand Down
6 changes: 6 additions & 0 deletions src/catnaplib/global/definitions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ const
"sourcemage": "sorcery",
"vanilla": "apx",
"venom": "scratchpkg",
"freebsd": "pkg",
"dragonfly": "pkg",
"netbsd": "pkgsrc",
"openbsd": "pkgsrc",
}.toOrderedTable
PKGCOUNTCOMMANDS* = static: {
"apx": "apx list -i | wc -l",
Expand All @@ -130,6 +134,8 @@ const
"zypper": "rpm -qa --last | wc --l",
"pacman": "pacman -Q | wc -l",
"apk": "apk list --installed | wc -l",
"pkg": "pkg info",
"pkgsrc": "pkg_info",
}.toOrderedTable

# Files / Dirs
Expand Down
7 changes: 5 additions & 2 deletions src/catnaplib/platform/probe.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ proc getDistro*(): string =
result = readCache(cacheFile)
if result != "": return

when defined(linux):
when defined(linux) or defined(bsd):
# Returns the name of the running linux distro
result = "/etc/os-release".loadConfig.getSectionValue("", "PRETTY_NAME") & " " & uname().machine
elif defined(macos):
Expand Down Expand Up @@ -75,7 +75,7 @@ proc getUser*(): string =

proc getKernel*(): string =
# Returns the active kernel version
result = "/proc/version".open.readLine.split(" ")[2]
result = uname().release

proc getParentPid(pid: int): int =
let statusFilePath = "/proc/" & $pid & "/status"
Expand Down Expand Up @@ -212,6 +212,9 @@ proc getCpu*(): string =
result = readCache(cacheFile)
if result != "":
return

when defined(macos):
return execCmd("sysctl -n machdep.cpu.brand_string")

let rawLines = readFile("/proc/cpuinfo").split("\n")

Expand Down

0 comments on commit d0e5d55

Please sign in to comment.