Merge pull request #49 from dylanaraps/stdout2
Add 'stdout' mode which allows you print the output in a lemonbar compatible format.
This commit is contained in:
commit
916c9c2cb1
37
1.1.md
37
1.1.md
|
@ -69,6 +69,43 @@ the distro ascii art and the automatic config creation.
|
|||
- Fetch now has a Gentoo/Funtoo e-build courtesy of @z1lt0id
|
||||
|
||||
|
||||
### Stdout
|
||||
|
||||
- Added `stdout` mode which allows you to fetch info in a plain text format that works<br \>
|
||||
with lemonbar and in your scripts. You can use it by launching fetch with `--stdout` to print all functions enabled<br \>
|
||||
in your `printinfo` function. You can selectively print functions by passing arguments to `--stdout`<br \>
|
||||
like so:
|
||||
|
||||
```sh
|
||||
# Print the output of all info functions enabled in printinfo
|
||||
fetch --stdout
|
||||
|
||||
# Print the output of memory
|
||||
fetch --stdout memory
|
||||
|
||||
# Print the output of memory and disk
|
||||
fetch --stdout disk
|
||||
|
||||
```
|
||||
|
||||
- Added `--stdout_seperator` and `$stdout_seperator` which takes a string and adds it<br \>
|
||||
as a seperator between the output.
|
||||
- Added `--stdout_title` and `$stdout_title` which allow you to toggle the `title@hostname`<br \>
|
||||
from appearing in the output.
|
||||
- Added `--stdout_subtitles` which allow you to toggle the `Info:` titles from appearing in<br \>
|
||||
the output.
|
||||
|
||||
```sh
|
||||
# Hiding subtitles
|
||||
fetch --stdout --stdout_subtitles off
|
||||
|
||||
# Custom seperator
|
||||
fetch --stdout disk gpu --stdout_seperator " | "
|
||||
|
||||
```
|
||||
|
||||
**NOTE:** `stdout_subtitles` and `stdout_title` only work when `--stdout` is used on its own.
|
||||
|
||||
### Info
|
||||
|
||||
- You can now display info without a subtitle. eg. `info memory`
|
||||
|
|
|
@ -297,6 +297,15 @@ alias fetch2="fetch \
|
|||
--ascii_distro distro Which Distro\'s ascii art to print
|
||||
|
||||
|
||||
Stdout:
|
||||
--stdout info info Launch fetch in stdout mode which prints the info
|
||||
in a plain-text format that you can use with
|
||||
lemonbar etc.
|
||||
--stdout_title on/off Hide/Show the title in stdout mode.
|
||||
--stdout_seperator string String to use as a seperator in stdout mode.
|
||||
--stdout_subtitles on/off Hide/Show the subtitles in stdout mode.
|
||||
|
||||
|
||||
Screenshot:
|
||||
--scrot /path/to/img Take a screenshot, if path is left empty the screen-
|
||||
shot function will use \$scrot_dir and \$scrot_name.
|
||||
|
|
|
@ -330,4 +330,20 @@ config="on"
|
|||
config_file="$HOME/.config/fetch/config"
|
||||
|
||||
|
||||
# }}}
|
||||
|
||||
# Other Options {{{
|
||||
|
||||
# Seperator to use in stdout mode.
|
||||
# --stdout_seperator string
|
||||
stdout_seperator=" "
|
||||
|
||||
# Hide/Show the title in stdout mode.
|
||||
# --stdout_title on/off
|
||||
stdout_title="off"
|
||||
|
||||
# Hide/Show each info's subtitle in stdout mode.
|
||||
# --stdout_subtitles on/off
|
||||
stdout_subtitles="on"
|
||||
|
||||
# }}}
|
||||
|
|
99
fetch
99
fetch
|
@ -350,6 +350,22 @@ config="on"
|
|||
config_file="$HOME/.config/fetch/config"
|
||||
|
||||
|
||||
# }}}
|
||||
|
||||
# Other Options {{{
|
||||
|
||||
# Seperator to use in stdout mode.
|
||||
# --stdout_seperator string
|
||||
stdout_seperator=" "
|
||||
|
||||
# Hide/Show the title in stdout mode.
|
||||
# --stdout_title on/off
|
||||
stdout_title="off"
|
||||
|
||||
# Hide/Show each info's subtitle in stdout mode.
|
||||
# --stdout_subtitles on/off
|
||||
stdout_subtitles="on"
|
||||
|
||||
# }}}
|
||||
|
||||
|
||||
|
@ -1222,8 +1238,8 @@ getbattery () {
|
|||
else
|
||||
# If there's only a single battery and it's battery 0,
|
||||
# don't number the subtitle.
|
||||
if [ "${#batteries[@]}" == 1 ] && [ "$battery_num" == 0 ]; then
|
||||
prin "${title}: ${batteries[0]}%"
|
||||
if [ "${#batteries[@]}" == 1 ]; then
|
||||
battery="${batteries[0]}%"
|
||||
return
|
||||
fi
|
||||
|
||||
|
@ -1782,6 +1798,11 @@ info () {
|
|||
string="${bold}${title_color}${output}"
|
||||
string="${string/@/${at_color}@${title_color}}"
|
||||
length=${#output}
|
||||
|
||||
# Hide the title in stdout mode
|
||||
[ "$stdout" == "on" ] && \
|
||||
[ "$stdout_title" == "off" ] &&\
|
||||
string=""
|
||||
;;
|
||||
|
||||
underline)
|
||||
|
@ -1799,7 +1820,22 @@ info () {
|
|||
[ -z "$2" ] && string=${string/*: }
|
||||
|
||||
# Print the string
|
||||
printf "%b%s\n" "${padding}${string}${clear}"
|
||||
if [ "$stdout" == "on" ]; then
|
||||
|
||||
# Unset the vars containg escape codes as lemonbar doesn't
|
||||
# support them.
|
||||
unset -v bold subtitle_color clear colon_color info_color \
|
||||
underline_color title_color at_color
|
||||
|
||||
# Show/Hide subtitles
|
||||
[ "$stdout_subtitles" == "off" ] && string=${string/*: }
|
||||
|
||||
# If the string isn't empty, print it.
|
||||
[ ! -z "$string" ] && printf "%s" "${string}${stdout_seperator}"
|
||||
|
||||
else
|
||||
printf "%b%s\n" "${padding}${string}${clear}"
|
||||
fi
|
||||
}
|
||||
|
||||
# }}}
|
||||
|
@ -1823,7 +1859,34 @@ prin () {
|
|||
;;
|
||||
esac
|
||||
|
||||
printf "%b%s\n" "${padding}${string}${clear}"
|
||||
# Print the info
|
||||
if [ "$stdout" == "on" ]; then
|
||||
printf "%s" "${string}${stdout_seperator}"
|
||||
else
|
||||
printf "%b%s\n" "${padding}${string}${clear}"
|
||||
fi
|
||||
}
|
||||
|
||||
# }}}
|
||||
|
||||
# Stdout {{{
|
||||
|
||||
stdout () {
|
||||
printinfo () {
|
||||
index=1
|
||||
for func in "${args[@]}"; do
|
||||
|
||||
case "$func" in
|
||||
"--stdout") continue ;;
|
||||
"--"*) break ;;
|
||||
*)
|
||||
case "${args[$((index + 1))]}" in "--"*) unset stdout_seperator ;; esac
|
||||
info "$func"
|
||||
;;
|
||||
esac
|
||||
index=$((index + 1))
|
||||
done
|
||||
}
|
||||
}
|
||||
|
||||
# }}}
|
||||
|
@ -2038,11 +2101,21 @@ usage () { cat << EOF
|
|||
--ascii_distro distro Which Distro\'s ascii art to print
|
||||
|
||||
|
||||
Stdout:
|
||||
--stdout info info Launch fetch in stdout mode which prints the info
|
||||
in a plain-text format that you can use with
|
||||
lemonbar etc.
|
||||
--stdout_title on/off Hide/Show the title in stdout mode.
|
||||
--stdout_seperator string String to use as a seperator in stdout mode.
|
||||
--stdout_subtitles on/off Hide/Show the subtitles in stdout mode.
|
||||
|
||||
|
||||
Screenshot:
|
||||
--scrot /path/to/img Take a screenshot, if path is left empty the screen-
|
||||
shot function will use \$scrot_dir and \$scrot_name.
|
||||
--scrot_cmd cmd Screenshot program to launch
|
||||
|
||||
|
||||
Other:
|
||||
--config /path/to/config Specify a path to a custom config file
|
||||
--config none Launch the script without a config file
|
||||
|
@ -2149,6 +2222,22 @@ while [ "$1" ]; do
|
|||
--scrot | -s) scrot="on"; [ "$2" ] && scrot_path="$2" ;;
|
||||
--scrot_cmd) scrot_cmd="$2" ;;
|
||||
|
||||
# Stdout
|
||||
--stdout_title) stdout_title="$2" ;;
|
||||
--stdout_seperator) stdout_seperator="$2" ;;
|
||||
--stdout_subtitles) stdout_subtitles="$2" ;;
|
||||
--stdout)
|
||||
case "$2" in
|
||||
"--"* | "") stdout="on" ;;
|
||||
*) stdout="on"; stdout_args="on"; args=("$@"); stdout ;;
|
||||
esac
|
||||
|
||||
unset info_color colors
|
||||
underline="off"
|
||||
image="off"
|
||||
color_blocks="off"
|
||||
;;
|
||||
|
||||
# Other
|
||||
--config)
|
||||
case "$2" in
|
||||
|
@ -2213,7 +2302,7 @@ fi
|
|||
[ "$image" != "off" ] && printf "\033[0H"
|
||||
|
||||
# Get colors / bold
|
||||
colors
|
||||
colors 2>/dev/null
|
||||
bold
|
||||
|
||||
# Print the info
|
||||
|
|
Reference in New Issue