evisum: add tingle command-line helper.

edi-0.5
Alastair Poole 4 years ago
parent 8076a4b96a
commit 93d48c1403
  1. 3
      NEWS
  2. 17
      README.md
  3. 4
      makefile
  4. 47
      src/tingle/README
  5. 23
      src/tingle/makefile
  6. 1689
      src/tingle/tingle.c
  7. 124
      src/tingle/tmux.conf
  8. 142
      src/tingle/volctl

@ -2,6 +2,9 @@
Evisum 0.2.0
============
* Add command-line utility (tingle) to complement
evisum.
* Fix object destruction befor exitting main loop.
* Add variable unit display (K, M and G).
* Minor refactoring.

@ -2,13 +2,10 @@
System Information (EFL)
This is a process monitor and system monitor.
This is a process monitor and system monitor for Linux, macOS,
FreeBSD, DragonFlyBSD and OpenBSD.
Currently have full engines for Linux, FreeBSD, OpenBSD and MacOS.
The plan is to rewrite the whole program to log system information
over time to disk so we can do nice things with E and displaying
system information (not duplicating loads of code).
Includes 'tingle' a command-line utility for displaying sensor information.
REQUIREMENTS:
@ -32,3 +29,11 @@ $ make PREFIX=/usr install
or even:
$ make PREFIX=/opt install
NOTES
The plan is to rewrite the whole program to log system information
over time to disk so we can do nice things with E and displaying
system information (not duplicating loads of code).
For information on tingle, see src/tingle/README.

@ -21,9 +21,10 @@ export LDFLAGS
default:
$(MAKE) -C src
$(MAKE) -C src/tingle
clean:
$(MAKE) -C src clean
$(MAKE) -C src/tingle clean
install:
-mkdir -p $(PREFIX)/share/pixmaps
@ -32,3 +33,4 @@ install:
install -m 0644 data/evisum.png $(PREFIX)/share/pixmaps
install -m 0644 data/evisum.desktop $(PREFIX)/share/applications
install -m 0755 evisum $(PREFIX)/bin
install -m 0755 src/tingle/tingle $(PREFIX)/bin

@ -0,0 +1,47 @@
# UNIX sensors (tingle)
# Query CPU, memory, network, power, audio and
temperature sensors.
Supporting Linux, FreeBSD, OpenBSD, Mac OS and DragonFlyBSD.
It's also probably a useful reference for querying common
system information on the most-common Unix-like operating
systems.
This can be used with pipes by other processes to
query the hardware. Or just to display a status
line in screen or tmux or some Xorg program.
If I'd thought more about it I'd have made it modular, so
apologies for the crust!
Install:
make (or gmake)
Usage: tingle [OPTIONS]
Where OPTIONS can be a combination of
-c
Show average CPU usage.
-C
Show all CPU cores and usage.
-k (KB) -m (MB) -g (GB)
Show memory usage (unit).
-n
Show network usage.
-p
Show power status (ac and battery percentage).
-t
Show temperature sensors (temperature in celcius).
-a
Display mixer values (system values).
-s
Show all in a nicely formatted status bar format.
This is the default behaviour with no arguments.
With other flags specify (in any order) which
components to display in the status bar.
-h | -help | --help
This help.
Al Poole <netstar@gmail.com>

@ -0,0 +1,23 @@
PROGRAM=tingle
SOURCES=tingle.c
CFLAGS=-O2 -Wall -pedantic -std=c99 -lpthread
LDFLAGS=-lm
HAVE_ALSA := 0
ALSA_TEST := $(shell pkg-config --exists alsa 1>&2 2>/dev/null; echo $$?)
HAVE_ALSA := $(shell if [ $(ALSA_TEST) -eq 0 ]; then echo "true"; else echo "false"; fi)
UNAME := $(shell uname -s)
ifeq ($(UNAME),Darwin)
CFLAGS += -framework AudioToolBox
else ifeq ($(UNAME),Linux)
ifeq ($(HAVE_ALSA),true)
CFLAGS += -lasound -DHAVE_ALSA=1
endif
endif
default:
$(CC) $(CFLAGS) $(LDFLAGS) $(SOURCES) -o tingle
clean:
-rm $(PROGRAM)

File diff suppressed because it is too large Load Diff

@ -0,0 +1,124 @@
set-option -g prefix C-j
unbind-key C-b
bind-key b send-prefix
# this is mainly taken from Richo Healey's dotfiles.
# thanks mate.
# TODO
# Finish mapping up all keys
# Learn how splits work
# WISHLIST
# Ideally, update the terminal title/hit the wm for activity on alert
# Statusline
set-window-option -g mode-keys vi # vi key
set-option -g status-keys vi
set -g default-terminal "screen-256color"
# What's the point of vi keys without pane movement?
bind l select-pane -R
bind k select-pane -U
bind j select-pane -D
bind h select-pane -L
bind < resize-pane -L 2
bind > resize-pane -R 2
bind - resize-pane -D 2
bind + resize-pane -U 2
bind ` next-layout
#Ctrl-j-u volume up
bind C-u run-shell -b 'volctl +10'
#Ctrl-j-j volume down
bind C-j run-shell -b 'volctl -10'
# copy mode to escape key
bind y copy-mode
bind ] paste-buffer
bind-key ^] send-keys Escape ":set paste\ri" \; paste-buffer\; send-keys Escape ":set nopaste\r"
#20:03 < micahcowan> rich0_, just in case, something like ^^ [that]
# move tmux copy buffer into x clipboard
bind-key C-y save-buffer /tmp/tmux-buffer \; run-shell "cat /tmp/tmux-buffer | xclip"
# splitting and cycling
unbind %
bind | split-window -h # horizontal split
unbind '"'
bind S split-window -v # vertical split
set-window-option -g automatic-rename off # auto name
# messages
set-window-option -g mode-bg black
set-window-option -g mode-fg white
#set-option -g message-bg nta
#set-option -g message-fg black
# No visual activity
set -g visual-activity off
set -g visual-bell on
set -g status-interval 120
# Less obnoxious colors
set -g pane-active-border-fg black
set -g pane-active-border-bg white
set -g pane-border-fg black
set -g pane-border-bg white
# Richo's screenlike bindings
bind C-n next
bind C-space next
bind space next
bind C-p prev
bind C-d detach
#unbind C-c
bind C-c new-window
bind K confirm-before kill-pane
bind A command-prompt "rename-window '%%'"
# bind M set-window-option monitor-activity (toggle)
# bind _ set-window-option monitor-silence 15 (Toggle)
bind-key C-a last-window
bind-key / command-prompt "split-window -h 'exec man %%'"
bind M set-window-option monitor-activity
bind _ command-prompt "setw monitor-silence '%%'"
bind I set-window-option synchronize-panes
# Create an environment that zsh can make sense of
# set-environment -g tmuxTERM $TERM
set-environment -g INSCREEN yes
# New shells should not inherit pwd
# set -g default-path "."
# status bar
set-option -g status-bg black
set-option -g status-fg white
set-option -g message-attr none
set-option -g message-bg black
set-option -g message-fg white
set-window-option -g window-status-bell-bg black
set-window-option -g window-status-bell-attr bright
set-window-option -g window-status-activity-bg red
set-window-option -g window-status-activity-attr bright
set-option -g status-interval 5
set-option -g status-right-length 90
set-option -g status-right "#[fg=colour255]#(tingle -s -c -m -a -p) #(date +'%H:%M %d-%m-%Y')"
# Cheers Nei on freenode
set-window-option -g window-status-current-format "[#[fg=white]#I:#W#F#[fg=red]]"
set-option -g visual-activity on
set-window-option -g monitor-activity off
set-window-option -g window-status-current-fg red
set-window-option -g window-status-current-attr bright
# DEBUG
# bind r source ~/.tmux.conf
# clock
set-window-option -g clock-mode-colour black
set-window-option -g clock-mode-style 24
# vim: ft=tmux

@ -0,0 +1,142 @@
#!/usr/bin/perl
use strict;
use warnings;
my $OS = $^O;
sub Error {
my ($str) = @_;
print STDERR "Error: $str\n";
exit (0 << 1);
}
sub mixer_levels_get {
my ($left, $right) = @_;
my $pipe_cmd = "";
if ($OS eq "openbsd" || $OS eq "netbsd")
{
$pipe_cmd = "mixerctl outputs.master|";
}
elsif ($OS eq "freebsd" || $OS eq "dragonfly")
{
$pipe_cmd = "mixer vol|";
}
elsif ($OS eq "darwin")
{
$pipe_cmd = "osascript -e 'get volume settings'|";
}
elsif ($OS eq "linux")
{
$pipe_cmd = "amixer get Master|";
}
open P, "$pipe_cmd" || die "Unable to determine mixer!\n";
my @lines = <P>;
close P;
my $have_mixer = 0;
foreach my $line (@lines)
{
if ($line =~ m/Left:.*\[(\d+)%\]/)
{
$$left = $1;
$have_mixer = 1;
}
if ($line =~ m/Right:.*\[(\d+)%\]/)
{
$$right = $1;
$have_mixer = 1;
}
if ($line =~ m/\Aoutput\svolume:(\d+),/)
{
$$left = $$right = $1;
return 1;
}
elsif ($line =~ m/(\d+),(\d+)/ || $line =~ m/(\d+):(\d+)/)
{
$$left = $1;
$$right = $2;
return 1;
}
}
return $have_mixer;
}
sub mixer_levels_set {
my ($new_left, $new_right) = @_;
my $cmd = "";
close (STDOUT);
if ($OS eq "openbsd" || $OS eq "netbsd")
{
$cmd = "mixerctl outputs.master=$new_left,$new_right";
}
elsif ($OS eq "freebsd" || $OS eq "dragonfly")
{
$cmd = "mixer $new_left:$new_right"
}
elsif ($OS eq "darwin")
{
my $greatest = $new_left > $new_right ? $new_left : $new_right;
my $ratio = 7 / 100;
my $volume = $greatest * $ratio;
$cmd = "osascript -e 'set volume $volume'";
}
elsif ($OS eq "linux")
{
my $greatest = $new_left > $new_right ? $new_left : $new_right;
$cmd = "amixer set \"Master\" $greatest%";
}
return system($cmd);
}
sub main {
my (@args) = @_;
my $argc = scalar(@args);
my ($inc, $dec) = (0, 0);
my ($left, $right) = (0, 0);
for (my $i = 0; $i < $argc; $i++)
{
if ($args[$i] =~ /\+(\d+)/)
{
$inc = $1;
}
if ($args[$i] =~ /\-(\d+)/)
{
$dec = $1
}
}
if (!mixer_levels_get(\$left, \$right))
{
Error("couldn't get current volumes");
}
$left -= $dec; $right -= $dec;
$left += $inc; $right += $inc;
if ($OS eq "linux" || $OS eq "darwin" || $OS eq "freebsd" || $OS eq "dragonfly")
{
if ($left < 0) { $left = 0; };
if ($left > 100) { $left = 100; };
if ($right < 0) { $right = 0; };
if ($right > 100) { $right = 100 };
}
return mixer_levels_set($left, $right);
}
exit(main(@ARGV));
Loading…
Cancel
Save