mirror of
https://github.com/lcpz/awesome-copycats.git
synced 2024-12-22 11:12:31 +00:00
better localization added
This commit is contained in:
parent
7beb6f6b44
commit
b259f7d99b
|
@ -1,9 +1,8 @@
|
|||
--[[ ]]--
|
||||
--
|
||||
-- -
|
||||
-- Blackburn Awesome WM 3.5.+ config --
|
||||
-- github.com/copycat-killer --
|
||||
-- -
|
||||
-- -
|
||||
--[[ ]]--
|
||||
|
||||
|
||||
|
@ -19,6 +18,7 @@ naughty = require("naughty")
|
|||
vicious = require("vicious")
|
||||
scratch = require("scratch")
|
||||
|
||||
|
||||
-- Run once function
|
||||
|
||||
function run_once(cmd)
|
||||
|
@ -179,7 +179,6 @@ mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
|
|||
coldef = "</span>"
|
||||
white = "<span color='#d7d7d7'>"
|
||||
gray = "<span color='#9e9c9a'>"
|
||||
red = "<span color='#e54c62'>"
|
||||
|
||||
|
||||
-- Textclock widget
|
||||
|
@ -193,7 +192,7 @@ local util = awful.util
|
|||
|
||||
char_width = nil
|
||||
text_color = theme.fg_normal or "#FFFFFF"
|
||||
today_color = theme.tasklist_fg_focus or "#FF7100"
|
||||
today_color = "#FF7100"
|
||||
calendar_width = 21
|
||||
|
||||
local calendar = nil
|
||||
|
@ -225,10 +224,21 @@ local function create_calendar()
|
|||
|
||||
local last_day = os.date("%d", os.time({ day = 1, year = cal_year,
|
||||
month = cal_month + 1}) - 86400)
|
||||
|
||||
local first_day = os.time({ day = 1, month = cal_month, year = cal_year})
|
||||
local first_day_in_week =
|
||||
os.date("%w", first_day)
|
||||
local first_day_in_week = os.date("%w", first_day)
|
||||
|
||||
local result = "do lu ma me gi ve sa\n" -- days of the week
|
||||
|
||||
-- Italian localization
|
||||
-- can be a stub for your own localization
|
||||
if os.setlocale():find("it_IT") == nil
|
||||
then
|
||||
result = "su mo tu we th fr sa\n"
|
||||
else
|
||||
result = "do lu ma me gi ve sa\n"
|
||||
end
|
||||
|
||||
for i = 1, first_day_in_week do
|
||||
result = result .. " "
|
||||
end
|
||||
|
@ -272,7 +282,7 @@ function remove_calendar()
|
|||
end
|
||||
end
|
||||
|
||||
function show(inc_offset)
|
||||
function add_calendar(inc_offset)
|
||||
inc_offset = inc_offset or 0
|
||||
|
||||
local save_offset = offset
|
||||
|
@ -297,10 +307,10 @@ function show_calendar(t_out)
|
|||
})
|
||||
end
|
||||
|
||||
mytextclock:connect_signal("mouse::enter", function() show(0) end)
|
||||
mytextclock:connect_signal("mouse::enter", function() add_calendar(0) end)
|
||||
mytextclock:connect_signal("mouse::leave", remove_calendar)
|
||||
mytextclock:buttons(util.table.join( awful.button({ }, 1, function() show(-1) end),
|
||||
awful.button({ }, 3, function() show(1) end)))
|
||||
mytextclock:buttons(util.table.join( awful.button({ }, 1, function() add_calendar(-1) end),
|
||||
awful.button({ }, 3, function() add_calendar(1) end)))
|
||||
|
||||
-- GMail widget
|
||||
mygmail = wibox.widget.textbox()
|
||||
|
@ -399,10 +409,20 @@ function show_info(t_out)
|
|||
mouse = mouse,
|
||||
screen = screen
|
||||
}
|
||||
local cal = awful.util.pread(scriptdir .. "dfs")
|
||||
cal = string.gsub(cal, " ^%s*(.-)%s*$", "%1")
|
||||
local hdd = awful.util.pread(scriptdir .. "dfs")
|
||||
hdd = string.gsub(hdd, " ^%s*(.-)%s*$", "%1")
|
||||
|
||||
-- Italian localization
|
||||
-- can be a stub for your own localization
|
||||
if os.setlocale():find("it_IT") ~= nil
|
||||
then
|
||||
hdd = string.gsub(hdd, "Used ", "Usato")
|
||||
hdd = string.gsub(hdd, "Free ", "Libero")
|
||||
hdd = string.gsub(hdd, "Total ", "Totale")
|
||||
end
|
||||
|
||||
infos = naughty.notify({
|
||||
text = cal,
|
||||
text = hdd,
|
||||
timeout = t_out,
|
||||
position = "top_right",
|
||||
margin = 10,
|
||||
|
@ -441,7 +461,7 @@ function (widget, args)
|
|||
return ''
|
||||
-- critical
|
||||
elseif (args[2] <= 5 and batstate() == 'Discharging') then
|
||||
naughty.notify({
|
||||
naughty.notify{
|
||||
text = "sto per spegnermi...",
|
||||
title = "Carica quasi esaurita!",
|
||||
position = "top_right",
|
||||
|
@ -450,7 +470,7 @@ function (widget, args)
|
|||
bg="#ffffff",
|
||||
screen = 1,
|
||||
ontop = true,
|
||||
})
|
||||
}
|
||||
-- low
|
||||
elseif (args[2] <= 10 and batstate() == 'Discharging') then
|
||||
naughty.notify({
|
||||
|
@ -493,7 +513,7 @@ function (widget, args)
|
|||
bg = beautiful.bg_normal })
|
||||
no_net_shown = false
|
||||
end
|
||||
return gray .. " Net " .. coldef .. red .. "Off " .. coldef
|
||||
return gray .. " Net " .. coldef .. "<span color='#e54c62'>Off " .. coldef
|
||||
else
|
||||
no_net_shown = true
|
||||
return ''
|
||||
|
@ -503,7 +523,7 @@ netwidget:buttons(awful.util.table.join(awful.button({ }, 1, function () awful.u
|
|||
|
||||
-- Weather widget
|
||||
require("perceptive")
|
||||
perceptive.register(1234567) -- replace with your city WOEID code
|
||||
perceptive.register(123456) -- fake code, enter your city one
|
||||
|
||||
-- Separators
|
||||
spr = wibox.widget.textbox(' ')
|
||||
|
@ -602,10 +622,10 @@ for s = 1, screen.count() do
|
|||
right_layout:add(spr)
|
||||
right_layout:add(perceptive.icon)
|
||||
right_layout:add(perceptive.widget)
|
||||
right_layout:add(spr)
|
||||
right_layout:add(memwidget)
|
||||
right_layout:add(spr)
|
||||
right_layout:add(tempwidget)
|
||||
--right_layout:add(spr)
|
||||
--right_layout:add(memwidget)
|
||||
--right_layout:add(spr)
|
||||
--right_layout:add(tempwidget)
|
||||
right_layout:add(fshwidget)
|
||||
right_layout:add(batwidget)
|
||||
right_layout:add(netwidget)
|
||||
|
|
388
scripts/dfs
Executable file
388
scripts/dfs
Executable file
|
@ -0,0 +1,388 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Adapted from Eridan's "fs" (cleanup, enhancements and switch to bash/Linux)
|
||||
# JM, 10/12/2004
|
||||
#
|
||||
# -------------------------------------------------------------------------
|
||||
# Decoding options
|
||||
# -------------------------------------------------------------------------
|
||||
USAGE="--> Usage: $0 [-h(elp)] | [-n(arrow mode)] | [-w(eb output)]"
|
||||
|
||||
NARROW_MODE=0
|
||||
WEB_OUTPUT=0
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
"-h" )
|
||||
echo $USAGE
|
||||
exit
|
||||
;;
|
||||
"-d" )
|
||||
DEBUG=1
|
||||
;;
|
||||
"-n" )
|
||||
NARROW_MODE=1
|
||||
;;
|
||||
"-w" )
|
||||
WEB_OUTPUT=1
|
||||
;;
|
||||
* )
|
||||
echo $USAGE
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Preparations
|
||||
# -------------------------------------------------------------------------
|
||||
SYSTEM=`uname -s`
|
||||
PATTERN="/"
|
||||
|
||||
case "$SYSTEM" in
|
||||
"Linux" )
|
||||
DF_COMMAND="/bin/df -k"
|
||||
SORT_COMMAND="/usr/bin/sort -k6"
|
||||
AWK_COMMAND="/bin/awk"
|
||||
;;
|
||||
* )
|
||||
DF_COMMAND="/bin/df -k"
|
||||
SORT_COMMAND="/usr/bin/sort -k6"
|
||||
AWK_COMMAND="/opt/local/bin/gawk"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ ! -x ${AWK_COMMAND} ]; then
|
||||
echo "### ${AWK_COMMAND} not present; install it! ###"
|
||||
echo " On Mac OS X: install MacPorts and perform:"
|
||||
echo " sudo port install gawk"
|
||||
fi
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Grabbing "df" result
|
||||
# -------------------------------------------------------------------------
|
||||
DF_RESULT=`$DF_COMMAND`
|
||||
if [ ! -z $DEBUG ]; then
|
||||
echo "--> DF_RESULT:"
|
||||
echo "$DF_RESULT"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Preprocessing "df" result, to join split logical lines
|
||||
# -------------------------------------------------------------------------
|
||||
PREPROCESSING_RESULT=` \
|
||||
echo "$DF_RESULT" | $AWK_COMMAND -v PATTERN=$PATTERN \
|
||||
'
|
||||
NF == 1 {
|
||||
printf ("%s", $0)
|
||||
}
|
||||
|
||||
NF == 5 {
|
||||
printf ("%s\n", $0)
|
||||
}
|
||||
|
||||
NF > 6 {
|
||||
}
|
||||
|
||||
NF == 6 {
|
||||
printf ("%s\n", $0)
|
||||
}'
|
||||
`
|
||||
if [ ! -z $DEBUG ]; then
|
||||
echo "--> PREPROCESSING_RESULT:"
|
||||
echo "$PREPROCESSING_RESULT"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
SORTED_FILE_SYSTEMS_INFO=`echo "$PREPROCESSING_RESULT" | $SORT_COMMAND`
|
||||
|
||||
if [ ! -z $DEBUG ]; then
|
||||
echo "--> SORTED_FILE_SYSTEMS_INFO:"
|
||||
echo "$SORTED_FILE_SYSTEMS_INFO"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Computing mount point max length
|
||||
# -------------------------------------------------------------------------
|
||||
MOUNT_POINT_MAX_LENGTH=` \
|
||||
echo $SORTED_FILE_SYSTEMS_INFO | $AWK_COMMAND -v PATTERN=$PATTERN \
|
||||
'
|
||||
BEGIN {
|
||||
mount_point_length_max = 15;
|
||||
}
|
||||
|
||||
END {
|
||||
printf ("%d", mount_point_length_max);
|
||||
}
|
||||
|
||||
$0 ~ PATTERN {
|
||||
# printf ("$6 = %s\n", $6);
|
||||
|
||||
mount_point = $6;
|
||||
# printf ("mount_point = %s\n", mount_point);
|
||||
|
||||
mount_point_length = length (mount_point);
|
||||
# printf ("mount_point_length = %d\n", mount_point_length);
|
||||
|
||||
if (mount_point_length > mount_point_length_max)
|
||||
mount_point_length_max = mount_point_length;
|
||||
}'
|
||||
`
|
||||
if [ ! -z $DEBUG ]; then
|
||||
echo "MOUNT_POINT_MAX_LENGTH: $MOUNT_POINT_MAX_LENGTH"
|
||||
fi
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Computing mount point data max size
|
||||
# -------------------------------------------------------------------------
|
||||
MOUNT_POINT_MAX_SIZE=` \
|
||||
echo "$SORTED_FILE_SYSTEMS_INFO" | $AWK_COMMAND -v PATTERN=$PATTERN \
|
||||
'
|
||||
BEGIN {
|
||||
mount_point_size_max = 0;
|
||||
}
|
||||
|
||||
END {
|
||||
printf ("%d", mount_point_size_max);
|
||||
}
|
||||
|
||||
$0 ~ PATTERN {
|
||||
# df -k shows k_bytes!
|
||||
# printf ("$2 = %s\n", $2);
|
||||
|
||||
mount_point_size = $2 * 1024;
|
||||
# printf ("mount_point_size = %d\n", mount_point_size);
|
||||
|
||||
if (mount_point_size > mount_point_size_max)
|
||||
mount_point_size_max = mount_point_size;
|
||||
}'
|
||||
`
|
||||
if [ ! -z $DEBUG ]; then
|
||||
echo "MOUNT_POINT_MAX_SIZE: $MOUNT_POINT_MAX_SIZE"
|
||||
fi
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Let's go!
|
||||
# -------------------------------------------------------------------------
|
||||
echo "$SORTED_FILE_SYSTEMS_INFO" | $AWK_COMMAND -v DEBUG=$DEBUG -v PATTERN=$PATTERN -v NARROW_MODE=$NARROW_MODE -v LEFT_COLUMN=$MOUNT_POINT_MAX_LENGTH -v MAX_SIZE=$MOUNT_POINT_MAX_SIZE -v SCALE=$SCALE -v WEB_OUTPUT=$WEB_OUTPUT \
|
||||
'
|
||||
# {printf ("$0 = %s\n", $0);}
|
||||
# {printf ("$1 = %s\n", $1);}
|
||||
# {printf ("PATTERN = %s\n", PATTERN);}
|
||||
# {printf ("LEFT_COLUMN = %s\n", LEFT_COLUMN);}
|
||||
|
||||
BEGIN {
|
||||
k_bytes = 1024.0;
|
||||
m_bytes = 1024.0 * k_bytes;
|
||||
g_bytes = 1024.0 * m_bytes;
|
||||
t_bytes = 1024.0 * g_bytes;
|
||||
|
||||
if (WEB_OUTPUT)
|
||||
{
|
||||
all_stars = "**************************************************";
|
||||
current_date = strftime ("%d-%m-%Y @ %H:%M:%S", localtime (systime ()));
|
||||
free_threshold = 10; # %
|
||||
|
||||
printf ("<!-- DEBUT CONTENU -->\n");
|
||||
|
||||
printf ( \
|
||||
"<A NAME=\"top\"></A>\n" \
|
||||
"<P ALIGN=CENTER><SPAN CLASS=\"titleblue\">%s</SPAN><SPAN CLASS=\"textbold\"> -- STATUS OF <SPAN CLASS=\"titlered\">ALCOR</SPAN> FILE SYSTEMS</SPAN></P><BR>\n",
|
||||
current_date )
|
||||
|
||||
printf ("<TABLE WIDTH=\"100%%\" BORDER=1>\n");
|
||||
|
||||
printf ( \
|
||||
"<TR>\n" \
|
||||
"<TD ALIGN=LEFT><STRONG>Mount point</STRONG></TD>\n" \
|
||||
"<TD ALIGN=CENTER><STRONG>%% Usato (<SPAN CLASS=\"titleblue\">*</SPAN>)" \
|
||||
" - %% Free (<SPAN CLASS=\"titlegreen\">*</SPAN>)</STRONG></TD>\n" \
|
||||
"<TD ALIGN=CENTER><STRONG>%% Usato</STRONG></TD>\n" \
|
||||
"<TD ALIGN=CENTER><STRONG>Spazio libero</STRONG></TD>\n" \
|
||||
"<TD ALIGN=CENTER><STRONG>Spazio totale</STRONG></TD>\n" \
|
||||
"</TR>\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
narrow_margin = " ";
|
||||
# printf ("%-*s", LEFT_COLUMN + 2, "Mount point");
|
||||
if (NARROW_MODE)
|
||||
printf ("\n%s", narrow_margin);
|
||||
else
|
||||
printf ("%-*s", LEFT_COLUMN + 2, "");
|
||||
print " Used Free Total ";
|
||||
if (! NARROW_MODE)
|
||||
print "";
|
||||
}
|
||||
}
|
||||
|
||||
END {
|
||||
if (WEB_OUTPUT)
|
||||
{
|
||||
printf ("</TABLE>\n");
|
||||
|
||||
printf ("<!-- FIN CONTENU -->\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (NARROW_MODE)
|
||||
printf ("%s", narrow_margin);
|
||||
else
|
||||
printf ("%-*s", LEFT_COLUMN + 2, "");
|
||||
print "|----|----|----|----|----|----|----|----|----|----|"
|
||||
if (NARROW_MODE)
|
||||
printf ("\n%s", narrow_margin);
|
||||
else
|
||||
printf ("%-*s", LEFT_COLUMN + 2, "");
|
||||
print "0 10 20 30 40 50 60 70 80 90 100";
|
||||
print "";
|
||||
}
|
||||
}
|
||||
|
||||
$0 ~ PATTERN {
|
||||
|
||||
if (index ($0, "members") == 0 && index ($0, "Download") == 0 && index ($0, "admin") == 0)
|
||||
{
|
||||
# df -k shows k_bytes!
|
||||
|
||||
total_size = $2 * k_bytes;
|
||||
free_size = $4 * k_bytes;
|
||||
percentage_occupied = substr($5, 0, 3);
|
||||
mount_point = $6;
|
||||
|
||||
percentage_free = int (100 - percentage_occupied);
|
||||
|
||||
# reduction_factor: 2
|
||||
stars_number = int (percentage_occupied / 2);
|
||||
|
||||
if (WEB_OUTPUT)
|
||||
{
|
||||
posGroup = index (mount_point, "scratch");
|
||||
if (posGroup == 0)
|
||||
posGroup = index (mount_point, "u1");
|
||||
if (posGroup == 0)
|
||||
posGroup = index (mount_point, "u2");
|
||||
if (posGroup == 0)
|
||||
posGroup = index (mount_point, "u4");
|
||||
if (posGroup == 0)
|
||||
posGroup = index (mount_point, "u5");
|
||||
|
||||
printf ("<TR>\n");
|
||||
|
||||
if (posGroup > 0 || percentage_free < free_threshold)
|
||||
{
|
||||
if (percentage_free < free_threshold)
|
||||
{
|
||||
class = "titlered";
|
||||
if (posGroup == 0)
|
||||
posGroup = 1; # to display the whole mount_point in this color anyway
|
||||
}
|
||||
else if ((index (mount_point, "scratch") != 0) || (index (mount_point, "u1") != 0) || (index (mount_point, "u2") != 0))
|
||||
{
|
||||
class = "titleorange";
|
||||
posGroup = 1; # to display the whole mount_point in this color
|
||||
}
|
||||
else if ((index (mount_point, "u4") != 0) || (index (mount_point, "u5") != 0))
|
||||
{
|
||||
class = "titlebrown";
|
||||
posGroup = 1; # to display the whole mount_point in this color
|
||||
}
|
||||
|
||||
printf ( \
|
||||
"<TD ALIGN=LEFT>%s<SPAN CLASS=\"%s\">%s</SPAN></TD>\n",
|
||||
substr (mount_point, 1, posGroup - 1),
|
||||
class,
|
||||
substr (mount_point, posGroup) );
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("<TD ALIGN=LEFT>%s</TD>\n", mount_point);
|
||||
}
|
||||
|
||||
printf ( \
|
||||
"<TD ALIGN=CENTER><SPAN CLASS=\"titleblue\">%s</SPAN><SPAN CLASS=\"titlegreen\">%s</SPAN></TD>\n",
|
||||
substr (all_stars, 1, stars_number), substr (all_stars, stars_number + 1, 49) );
|
||||
|
||||
if (percentage_free < free_threshold)
|
||||
{
|
||||
color_beginning = "<SPAN CLASS=\"titlered\">";
|
||||
color_end = "</SPAN>"
|
||||
}
|
||||
else
|
||||
{
|
||||
color_beginning = "";
|
||||
color_end = ""
|
||||
}
|
||||
|
||||
if (total_size > 1 * t_bytes)
|
||||
printf ( \
|
||||
"<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Tb</TD><TD ALIGN=RIGHT>%5.1f Tb</TD>\n", \
|
||||
color_beginning, percentage_occupied, color_end, free_size / t_bytes, total_size / t_bytes \
|
||||
);
|
||||
else if (total_size > 1 * g_bytes)
|
||||
printf ( \
|
||||
"<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Gb</TD><TD ALIGN=RIGHT>%5.1f Gb</TD>\n", \
|
||||
color_beginning, percentage_occupied, color_end, free_size / g_bytes, total_size / g_bytes \
|
||||
);
|
||||
else if (total_size > 1 * m_byptes)
|
||||
printf ( \
|
||||
"<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Mb</TD><TD ALIGN=RIGHT>%5.1f Mb</TD>\n", \
|
||||
color_beginning, percentage_occupied, color_end, free_size / m_bytes, total_size / m_bytes \
|
||||
);
|
||||
else
|
||||
printf ( \
|
||||
"<TD ALIGN=RIGHT>%s%3d%%%s</TD><TD ALIGN=RIGHT>%5.1f Kb</TD><TD ALIGN=RIGHT>%5.1f Kb</TD>\n", \
|
||||
color_beginning, percentage_occupied, color_end, free_size / k_bytes, total_size / k_bytes \
|
||||
);
|
||||
|
||||
printf ("</TR>\n");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
# printf ("percentage_occupied = %d\n", percentage_occupied);
|
||||
# printf ("percentage_free = %d\n", percentage_free);
|
||||
|
||||
printf ("%-*s", LEFT_COLUMN + 2, mount_point);
|
||||
if (NARROW_MODE)
|
||||
printf ("\n%s", narrow_margin);
|
||||
|
||||
# printf ("stars_number = %d\n", stars_number);
|
||||
|
||||
printf ("|");
|
||||
for (i = 1; i <= stars_number; i++)
|
||||
{
|
||||
printf ("%s", "*");
|
||||
}
|
||||
for (i = stars_number + 1; i <= 49; i++)
|
||||
{
|
||||
printf ("%s", "-");
|
||||
}
|
||||
|
||||
|
||||
if (total_size > 1 * t_bytes)
|
||||
printf ( \
|
||||
"| %3d%% %5.1f %5.1f Tb\n", \
|
||||
percentage_occupied, free_size / t_bytes, total_size / t_bytes \
|
||||
);
|
||||
else if (total_size > 1 * g_bytes)
|
||||
printf ( \
|
||||
"| %3d%% %5.1f %5.1f Gb\n", \
|
||||
percentage_occupied, free_size / g_bytes, total_size / g_bytes \
|
||||
);
|
||||
else if (total_size > 1 * m_byptes)
|
||||
printf ( \
|
||||
"| %3d%% %5.1f %5.1f Mb\n", \
|
||||
percentage_occupied, free_size / m_bytes, total_size / m_bytes \
|
||||
);
|
||||
else
|
||||
printf ( \
|
||||
"| %3d%% %5.1f %5.1f Kb\n", \
|
||||
percentage_occupied, free_size / k_bytes, total_size / k_bytes \
|
||||
);
|
||||
}
|
||||
} # if
|
||||
}'
|
88
scripts/mpdinfo
Executable file
88
scripts/mpdinfo
Executable file
|
@ -0,0 +1,88 @@
|
|||
#!/bin/bash
|
||||
|
||||
# A simple notify script for now-playing songs on mpd. This script uses
|
||||
# notify-send and mpc to get the current song information.
|
||||
|
||||
# Requirements (* = optional)
|
||||
# - mpd
|
||||
# - mpc
|
||||
# - notify-send (libnotify)
|
||||
# * ImageMagick (convert)
|
||||
|
||||
# Author : Wolfgang Mueller
|
||||
# You can use, edit and redistribute this script in any way you like.
|
||||
# (Just make sure not to hurt any kittens)
|
||||
|
||||
# Configuration-------------------------------------------------------
|
||||
|
||||
# The music directory that contains the music and cover files
|
||||
MUSIC_DIR="$HOME/Musica"
|
||||
|
||||
# The default cover to use (optional)
|
||||
DEFAULT_ART=""
|
||||
|
||||
# The following track metadata delimiters can be changed.
|
||||
# You can find all possible delimiters in the 'mpc' manpage.
|
||||
# It's also possible to use pango markup like <u></u> and <i></i>
|
||||
|
||||
# How to format artist/album information
|
||||
A_FORMAT="%artist%[ (%album%)] - %date%"
|
||||
|
||||
# How to format title information
|
||||
T_FORMAT="%title%"
|
||||
|
||||
# Regex expression used for image search
|
||||
IMG_REG="(front|cover|art|Folder|folder)\.(jpg|jpeg|png|gif)$"
|
||||
|
||||
# Title of the notification
|
||||
NOTIFY_TITLE="Now Playing"
|
||||
|
||||
# Path of temporary resized cover
|
||||
TEMP_PATH="/tmp/mpdnotify_cover.png"
|
||||
|
||||
# Resize cover to (optional, recommended)
|
||||
COVER_RESIZE="100x100"
|
||||
|
||||
# Thumbnail background (transparent by default)
|
||||
COVER_BACKGROUND="none"
|
||||
|
||||
# Logfile
|
||||
LOGFILE="$HOME/.mpdnotify.log"
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
|
||||
# determine file
|
||||
file="$(mpc current -f %file%)"
|
||||
|
||||
# check if anything is playing at all
|
||||
[[ -z $file ]] && exit 1
|
||||
|
||||
# Get title info
|
||||
title="$(mpc current -f "$A_FORMAT")"
|
||||
|
||||
# Get song info
|
||||
song="$(mpc current -f "$T_FORMAT")"
|
||||
|
||||
# Art directory
|
||||
art="$MUSIC_DIR/${file%/*}"
|
||||
|
||||
# find every file that matches IMG_REG set the first matching file to be the
|
||||
# cover.
|
||||
cover="$(find "$art/" -maxdepth 1 -type f | egrep -i -m1 "$IMG_REG")"
|
||||
|
||||
# when no cover is found, use DEFAULT_ART as cover
|
||||
cover="${cover:=$DEFAULT_ART}"
|
||||
|
||||
# check if art is available
|
||||
if [[ -n $cover ]]; then
|
||||
|
||||
if [[ -n $COVER_RESIZE ]]; then
|
||||
convert "$cover" -thumbnail $COVER_RESIZE -gravity center \
|
||||
-background "$COVER_BACKGROUND" -extent $COVER_RESIZE "$TEMP_PATH" >> "$LOGFILE" 2>&1
|
||||
cover="$TEMP_PATH"
|
||||
fi
|
||||
|
||||
notify-send -t 5000 --hint=int:transient:1 "$NOTIFY_TITLE" "$title\n$song" -i "$cover" >> "$LOGFILE" 2>&1
|
||||
else
|
||||
notify-send -t 5000 --hint=int:transient:1 "$NOTIFY_TITLE" "$title\n$song" >> "$LOGFILE" 2>&1
|
||||
fi
|
Loading…
Reference in a new issue