Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qbar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jens Nolte
qbar
Commits
27911553
Commit
27911553
authored
4 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Implement simple disk usage block based on coreutils `df`
parent
86e48bf0
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/QBar/Blocks.hs
+2
-0
2 additions, 0 deletions
src/QBar/Blocks.hs
src/QBar/Blocks/DiskUsage.hs
+31
-0
31 additions, 0 deletions
src/QBar/Blocks/DiskUsage.hs
src/QBar/Cli.hs
+6
-0
6 additions, 0 deletions
src/QBar/Cli.hs
stack.yaml
+1
-1
1 addition, 1 deletion
stack.yaml
with
40 additions
and
1 deletion
src/QBar/Blocks.hs
+
2
−
0
View file @
27911553
...
...
@@ -2,6 +2,7 @@ module QBar.Blocks
(
QBar
.
Blocks
.
Battery
.
batteryBlock
,
QBar
.
Blocks
.
CpuUsage
.
cpuUsageBlock
,
QBar
.
Blocks
.
Date
.
dateBlock
,
QBar
.
Blocks
.
DiskUsage
.
diskUsageBlock
,
QBar
.
Blocks
.
NetworkManager
.
networkManagerBlock
,
QBar
.
Blocks
.
Script
.
scriptBlock
,
QBar
.
Blocks
.
Script
.
pollScriptBlock
,
...
...
@@ -11,5 +12,6 @@ where
import
qualified
QBar.Blocks.Battery
import
qualified
QBar.Blocks.CpuUsage
import
qualified
QBar.Blocks.Date
import
qualified
QBar.Blocks.DiskUsage
import
qualified
QBar.Blocks.NetworkManager
import
qualified
QBar.Blocks.Script
This diff is collapsed.
Click to expand it.
src/QBar/Blocks/DiskUsage.hs
0 → 100644
+
31
−
0
View file @
27911553
module
QBar.Blocks.DiskUsage
where
import
QBar.BlockHelper
import
QBar.BlockOutput
import
QBar.Core
import
qualified
Data.ByteString.Lazy.Char8
as
C8
import
qualified
Data.Text.Lazy
as
T
import
qualified
Data.Text.Lazy.Encoding
as
T
import
System.Exit
import
System.Process.Typed
(
shell
,
readProcessStdout
)
diskIcon
::
T
.
Text
diskIcon
=
"💾
\xFE0E
"
diskUsageBlock
::
Text
->
Block
diskUsageBlock
path
=
runPollBlock
$
forever
$
do
output
<-
liftBarIO
action
yieldBlockUpdate
$
addIcon
diskIcon
output
where
action
::
BarIO
BlockOutput
action
=
do
(
exitCode
,
output
)
<-
liftIO
$
readProcessStdout
$
shell
$
"df --human-readable --local --output=avail "
<>
T
.
unpack
path
return
$
case
exitCode
of
ExitSuccess
->
createBlockOutput
output
(
ExitFailure
nr
)
->
mkErrorOutput
$
"exit code "
<>
T
.
pack
(
show
nr
)
<>
""
createBlockOutput
::
C8
.
ByteString
->
BlockOutput
createBlockOutput
output
=
case
map
T
.
decodeUtf8
(
C8
.
lines
output
)
of
[]
->
mkErrorOutput
$
"no output"
[
_header
]
->
mkErrorOutput
$
"invalid output"
(
_header
:
values
)
->
mkBlockOutput
$
normalText
$
T
.
intercalate
" "
$
map
T
.
strip
values
This diff is collapsed.
Click to expand it.
src/QBar/Cli.hs
+
6
−
0
View file @
27911553
...
...
@@ -88,10 +88,16 @@ blockParser =
command
"date"
(
info
(
pure
$
addBlock
dateBlock
)
(
progDesc
"Load the date and time block."
))
<>
command
"cpu"
(
info
(
pure
$
addBlock
$
cpuUsageBlock
1
)
(
progDesc
"Load the cpu usage block."
))
<>
command
"battery"
(
info
(
pure
$
addBlock
$
batteryBlock
)
(
progDesc
"Load the battery block."
))
<>
command
"disk"
(
info
diskUsageBlockParser
(
progDesc
"Load the disk usage block."
))
<>
command
"networkmanager"
(
info
(
pure
$
addBlock
networkManagerBlock
)
(
progDesc
"Load the network-manager block."
))
<>
command
"script"
(
info
scriptBlockParser
(
progDesc
"Display the output of an external script as a block."
))
)
diskUsageBlockParser
::
Parser
(
BarIO
()
)
diskUsageBlockParser
=
do
file
<-
strArgument
(
metavar
"FILE"
<>
help
"The FILE by which the file system is selected."
)
return
$
addBlock
$
diskUsageBlock
file
scriptBlockParser
::
Parser
(
BarIO
()
)
scriptBlockParser
=
helper
<*>
do
poll
<-
switch
$
long
"poll"
<>
short
'p'
<>
help
"Run script in poll mode (at regular intervals)"
...
...
This diff is collapsed.
Click to expand it.
stack.yaml
+
1
−
1
View file @
27911553
...
...
@@ -42,7 +42,7 @@ packages:
# Disable pure nix-shell environment on NixOS, because access to XDG_RUNTIME_DIR is needed for the control socket
nix
:
pure
:
false
packages
:
[
zlib
]
packages
:
[
zlib
coreutils
]
# Override default flag values for local packages and extra-deps
# flags: {}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment