constantin-net

awesomewm_examples_comp

Aug 21st, 2018 (edited)
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.55 KB | None | 0 0
  1. -- dynamic_pread
  2. mymount = awful.widget.button({ image = '/home/piyavking/.local/share/icons/mount.png' })
  3. mymount:buttons(awful.util.table.join(
  4.             awful.button({ }, 1, function()
  5.  
  6.     myflashstatus = awful.util.pread("mount | grep \/dev\/sdc1")
  7.     if myflashstatus == "" then
  8.             myflashname = 'Mount Flash'
  9.             myflashcommand = 'sudo mount -o noatime,nodiratime,rw /dev/sdc1 /flash'
  10.     else
  11.             myflashname = 'Umount Flash'
  12.             myflashcommand = 'sudo umount /dev/sdc1'
  13.     end
  14.  
  15.     mycdstatus = awful.util.pread("mount | grep \/dev\/sr0")
  16.     if myflashstatus == "" then
  17.             mycdname = 'Mount CD/DVD'
  18.             mycdcommand = 'sudo mount -o noatime,nodiratime,ro /dev/sr0 /cdrom'
  19.     else
  20.             mycdname = 'Umount CD/DVD'
  21.             mycdcommand = 'sudo umount /dev/sr0'
  22.     end
  23.  
  24.     myntfsstatus = awful.util.pread("mount | grep \/dev\/sdb3")
  25.     if myntfsstatus == "" then
  26.             myntfsname = 'Mount NTFS'
  27.             myntfscommand = 'sudo mount -o noatime,nodiratime,rw /dev/sdb3 /ntfs'
  28.     else
  29.             myntfsname = 'Umount NTFS'
  30.             myntfscommand = 'sudo umount /dev/sdb3'
  31.     end
  32.  
  33.     mygdiskstatus = awful.util.pread("mount | grep google-drive")
  34.     if mygdiskstatus == "" then
  35.             mygdiskname = 'Mount Google Drive'
  36.             mygdiskcommand = 'google-drive-ocamlfuse /home/piyavking/google-drive'
  37.     else
  38.             mygdiskname = 'Umount Google Drive'
  39.             mygdiskcommand = 'fusermount -u /home/piyavking/google-drive'
  40.     end
  41.  
  42.     mymountmenu = awful.menu({ items = {
  43.     { myflashname, myflashcommand, '/home/piyavking/.local/share/icons/mount.png' },
  44.     { mycdname, mycdcommand, '/home/piyavking/.local/share/icons/mount.png' },
  45.     { myntfsname, myntfscommand, '/home/piyavking/.local/share/icons/mount.png' },
  46.     { mygdiskname, mygdiskcommand, '/home/piyavking/.local/share/icons/mount.png' }
  47.     }
  48.     })
  49.  
  50.     mymountmenu:show()
  51.     end )
  52. ))
  53.  
  54.  
  55. -- mocp.lua
  56.  
  57.  local io = io
  58.  local string = string
  59.  local awful = require("awful")
  60.  local beautiful = require("beautiful")
  61.  local naughty = require("naughty")
  62.  local markup = require("markup")
  63.  
  64.  module("mocp")
  65.  
  66.  -- public settings
  67.  settings = {}
  68.  settings.iScroller = 1
  69.  settings.MAXCH = 15
  70.  settings.interval = 0.75
  71.  
  72.  local mocbox = nil
  73.  local trackinfo = {}
  74.  trackinfo.artist = ""
  75.  trackinfo.songtitle = ""
  76.  trackinfo.album = ""
  77.  trackinfo.state = ""
  78.  
  79.  ---PAUSE
  80.  
  81.  ---{{{ local setTitle
  82.  -- call to force update of trackinfo variables
  83.  local function setTitle()
  84.  
  85.    local fd = {}
  86.  
  87.    if state() then
  88.        fd = io.popen('mocp -i')
  89.  
  90.        -- read to end of mocp -i
  91.        tmp = fd:read()
  92.        while tmp ~= nil do
  93.            key = string.match(tmp,"^%w+")
  94.            if trackinfo[key:lower()] ~= nil then
  95.                trackinfo[key:lower()]=awful.util.escape(string.gsub(string.gsub(tmp,key..":%s*",""),"%b()",""))
  96.            end
  97.            tmp = fd:read()
  98.        end
  99.    end
  100.  
  101.  end
  102.  ---}}}
  103.  
  104.  ---{{{ local title(delim)
  105.  local function title(delim)
  106.  
  107.    local eol = delim or " "
  108.    local np = {}
  109.  
  110.    if trackinfo.artist == "" and state() then setTitle() end
  111.    np.song =string.gsub( string.gsub(trackinfo.songtitle,"^%d*",""),"%(.*","") .. eol
  112.  
  113.    -- return for widget text
  114.    return trackinfo.artist.." : "..np.song
  115.  
  116.  end
  117.  ---}}}
  118.  
  119.  ---{{{ local function notdestroy()
  120.  local function notdestroy()
  121.    if mocbox ~= nil then
  122.        naughty.destroy(mocbox)
  123.        mocbox = nil
  124.    end
  125.  end
  126.  ---}}}
  127.  
  128.  ---{{{ local getTime() gets ct and tt of track for popup
  129.  --@return string containig formatted times
  130.  local function getTime()
  131.    local fd = {}
  132.    local ttable = {}
  133.    fd = io.popen('mocp -i')
  134.    local tmp = fd:read()
  135.  
  136.    while tmp ~= nil do
  137.        key = string.match(tmp,"^%w+")
  138.        if key == "TotalTime" then
  139.            tstring = " [ "..markup.fg(beautiful.fg_normal,awful.util.escape(string.gsub(string.gsub(tmp,key..":%s*",""),"%b()",""))).." ]"
  140.        elseif key == "CurrentTime" then
  141.            tstring = markup.fg(beautiful.fg_focus,"Time:   ")..
  142.                      markup.fg(beautiful.fg_normal,awful.util.escape(string.gsub(string.gsub(tmp,key..":%s*",""),"%b()","")))..tstring
  143.        end
  144.        tmp = fd:read()
  145.    end
  146.  
  147.    fd:close()
  148.  
  149.    return tstring
  150.  end
  151.  ---}}}
  152.  
  153.  ---{{{ popup
  154.  -- displays a naughty notificaiton of the current track
  155.  function popup()
  156.    
  157.    setTitle()
  158.    notdestroy()
  159.  
  160.    local np = {}
  161.    np.state = nil
  162.    np.strng = ""
  163.    if not state() then
  164.        return
  165.    else
  166.        np.strng = "Artist: "..markup.fg(beautiful.fg_normal,trackinfo.artist).."\n"..
  167.                   "Song:   "..markup.fg(beautiful.fg_normal,trackinfo.songtitle).."\n"..
  168.                   "Album:  "..markup.fg(beautiful.fg_normal,trackinfo.album).."\n"
  169.        np.strng = np.strng..markup.fg(beautiful.fg_normal,getTime())
  170.    end
  171.    np.strng = markup.fg( beautiful.fg_focus, markup.font("monospace", np.strng.."  "))  
  172.    mocbox = naughty.notify({
  173.        title = markup.font("monospace","Now Playing:"),
  174.        text = np.strng, hover_timeout = ( settings.hovertime or 3 ), timeout = 0,
  175.        -- icon = "/usr/share/icons/gnome/24x24/actions/edia-playback-start.png", icon_size = 24,
  176.          run = function() play(); popup() end
  177.      })
  178.  end
  179.  ---}}}
  180.  
  181.  ---run mocp
  182.  function play()
  183.    if trackinfo.state == "STOP" then
  184.     awful.util.spawn('mocp --play')
  185.    elseif trackinfo.state == "PLAY" then
  186.      awful.util.spawn('mocp --next')
  187.    else
  188.      awful.util.spawn('mocp --toggle-pause')
  189.  end
  190.  end
  191.  ---
  192.  
  193.  function setwidget(w)
  194.    settings.widget = w
  195.    awful.hooks.timer.register (settings.interval,scroller)
  196.    state()
  197.  end
  198.  
  199.  ---{{{ function update ( k, v)
  200.  -- called by any kind of external script to trigger widget text update
  201.  function update ( k, v )
  202.    if #k == 0 or #v == 0 then return end
  203.    if trackinfo[k] ~= nil then
  204.        trackinfo[k] = v
  205.    end
  206.    state()
  207.  end
  208.  ---}}}
  209.  
  210.  -- mocp widget, scrolls text
  211.  function scroller(tb)
  212.    local np = {}
  213.  
  214.    -- if mocp is not running, then simply return here
  215.    if trackinfo.state == "OFF" then
  216.        settings.iScroller = 1
  217.        state()
  218.        return
  219.    else
  220.        -- this sets the symbolic prefix based on where moc is playing or stopped or paused
  221.        if trackinfo.state == "PAUSE" then
  222.            prefix = "|| "
  223.            settings.interval = 2
  224.        elseif trackinfo.state == "STOP" then
  225.            settings.iScroller = 1
  226.            settings.widget.width = 20
  227.            settings.widget.text = "[]"
  228.            return
  229.        else
  230.            prefix = ">> "
  231.            settings.interval = 0.75
  232.        end
  233.  
  234.        -- extract a substring, putting it after the
  235.        np.strng = title()
  236.        np.rtn = string.sub(np.strng,settings.iScroller,settings.MAXCH+settings.iScroller-1)
  237.  
  238.        -- if our index and settings.MAXCH count are bigger than the string, wrap around to the beginning and
  239.        -- add enough to make it look circular
  240.        if settings.MAXCH+settings.iScroller > (np.strng):len() then
  241.            np.rtn = np.rtn .. string.sub(np.strng,1,(settings.MAXCH+settings.iScroller-1)-np.strng:len())
  242.        end
  243.  
  244.        np.rtn = awful.util.escape(np.rtn)
  245.        settings.widget.text = markup.fg(beautiful.fg_normal,prefix) .. markup.fg(beautiful.fg_sb_hi,np.rtn)
  246.  
  247.        if settings.iScroller <= np.strng:len() then
  248.            settings.iScroller = settings.iScroller +1
  249.        else
  250.            settings.iScroller = 1
  251.        end
  252.    end
  253.  end
  254.  -- }}}
  255.  
  256.  
  257.  
  258. --shutdown_dialog.sh
  259. #!/bin/sh
  260. ACTION=$(
  261.  
  262. zenity --list --width=500 --height=250 --radiolist \
  263.        --title="Опции выключения" \
  264.        --column="Выбор" --column="Опция" \
  265.        FALSE quit TRUE halt FALSE reboot FALSE sleep
  266.  
  267. )
  268. if [ -n "${ACTION}" ];then
  269.   case $ACTION in
  270.   quit)
  271.   echo "awesome.quit()" | awesome-client
  272.     ;;
  273.   halt)
  274.     gksu halt
  275.     ;;
  276.   reboot)
  277.     gksu reboot
  278.     ;;
  279.   sleep)
  280.     gksu pm-suspend
  281.     ;;
  282.   esac
  283. fi
  284.  
  285.  
  286.  
  287. -- table hisory prompt
  288. local function history_check_load(id, max)
  289.     if id and id ~= ""
  290.         and not data.history[id] then
  291.     data.history[id] = { max = 50, table = {} }
  292.  
  293.     if max then
  294.             data.history[id].max = max
  295.     end
  296.  
  297.     local f = io.open(id, "r")
  298.  
  299.     -- Read history file
  300.     if f then
  301.             for line in f:lines() do
  302.                 if util.table.hasitem(data.history[id].table, line) == nil then
  303.                         table.insert(data.history[id].table, line)
  304.                         if #data.history[id].table >= data.history[id].max then
  305.                            break
  306.                         end
  307.                 end
  308.             end
  309.             f:close()
  310.     end
  311.     end
  312. end
Add Comment
Please, Sign In to add comment