├── bin ├── README.md ├── run_once ├── volume ├── brightness └── batteryd ├── README.md ├── init ├── README.md └── batteryd.conf ├── install └── pm └── 20_suspend_brightness_fix /bin/README.md: -------------------------------------------------------------------------------- 1 | Contains useful binaries that I want on my machine. 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Laptop Configs 2 | ============== 3 | 4 | Laptop Configuration Files for backlight, volume, acpi etc. 5 | -------------------------------------------------------------------------------- /init/README.md: -------------------------------------------------------------------------------- 1 | This folder contains some custom daemons that I've written to notify me of 2 | Laptop events such as Low Battery. 3 | -------------------------------------------------------------------------------- /bin/run_once: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # Run program unless it's already running. 4 | # Stolen from http://awesome.naquadah.org/wiki/Autostart 5 | 6 | pgrep $@ > /dev/null || ($@ &) 7 | -------------------------------------------------------------------------------- /init/batteryd.conf: -------------------------------------------------------------------------------- 1 | description "Battery Daemon" 2 | author "Vaibhav Verma " 3 | 4 | start on runlevel [2345] 5 | stop on runlevel [016] 6 | 7 | exec /usr/sbin/batteryd 8 | -------------------------------------------------------------------------------- /bin/volume: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This script adjusts your laptop's volume 3 | # This assumes that you are running Alsamixer 4 | 5 | 6 | case $1 in 7 | up) 8 | amixer set Master 2%+ 9 | ;; 10 | down) 11 | amixer set Master 2%- 12 | ;; 13 | mute) 14 | amixer set Master toggle 15 | ;; 16 | *) 17 | echo "Valid options are volume up|down|mute" 18 | ;; 19 | esac 20 | -------------------------------------------------------------------------------- /bin/brightness: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This script adjusts your laptop's brightness. 3 | # In order to use this, your /sys/class/backlight/acpi_video0/brightness should be writeable 4 | 5 | 6 | FILE=/sys/class/backlight/acpi_video0/brightness 7 | 8 | current_brightness=`cat $FILE` 9 | 10 | case $1 in 11 | up) 12 | new_brightness=`expr $current_brightness + 6` 13 | ;; 14 | down) 15 | new_brightness=`expr $current_brightness - 6` 16 | ;; 17 | *) 18 | echo $current_brightness 19 | exit; 20 | ;; 21 | esac 22 | echo $new_brightness > $FILE 23 | -------------------------------------------------------------------------------- /install: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Check out submodules. The --git-dir option doesn't work here. 4 | cd "${HOME}/laptop_configs" 5 | git submodule --quiet update --init 6 | cd "${OLDPWD}" 7 | 8 | # Link in files, replacing whatever's already there. 9 | mkdir -p ${HOME}/bin 10 | ln -fs "${HOME}/laptop_configs/bin/brightness" "${HOME}/bin/" 11 | ln -fs "${HOME}/laptop_configs/bin/volume" "${HOME}/bin/" 12 | ln -fs "${HOME}/laptop_configs/bin/run_once" "${HOME}/bin/" 13 | sudo ln -fs "${HOME}/laptop_configs/pm/20_suspend_brightness_fix" "/etc/pm/sleep.d/" 14 | 15 | # Put the battery daemon in place. 16 | sudo ln -fs "${HOME}/laptop_configs/init/batteryd.conf" "/etc/init/" 17 | sudo ln -fs "${HOME}/laptop_configs/bin/batteryd" "/usr/sbin/" 18 | 19 | # Start the battery daemon 20 | sudo initctl reload-configuration 21 | sudo start batteryd 22 | -------------------------------------------------------------------------------- /pm/20_suspend_brightness_fix: -------------------------------------------------------------------------------- 1 | # !/bin/bash 2 | # 3 | # This script restores screen backlight on resume from suspend 4 | # on Samsung NP900X3B/C. 5 | # 6 | # This should be placed in /etc/pm/sleep.d 7 | # Stolen from https://help.ubuntu.com/community/SamsungSeries9 8 | case "$1" in 9 | suspend|hibernate) 10 | # do nothing 11 | ;; 12 | 13 | resume|thaw) 14 | # brightness value is not always accurate. Set to actual_brightness 15 | # to restore brightness as it was before suspend. 16 | echo `cat /sys/class/backlight/intel_backlight/actual_brightness` > /sys/class/backlight/intel_backlight/brightness 17 | 18 | # Toggle to activate the screen backlight 19 | echo 1 > "/sys/class/backlight/intel_backlight/bl_power" 20 | echo 0 > "/sys/class/backlight/intel_backlight/bl_power" 21 | ;; 22 | *) 23 | exit 1 24 | esac 25 | exit 0 26 | -------------------------------------------------------------------------------- /bin/batteryd: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # This is a simple script that notifies you when your battery is low using libnotify. 3 | # It can easily be changed to hibernate/sleep your machine. 4 | import pynotify 5 | import re 6 | import time 7 | 8 | limit = 1000 9 | sleeptime = 60 #seconds 10 | sleep_command = "/usr/sbin/pm-hibernate" 11 | 12 | 13 | def get_battery_status(): 14 | filename = '/proc/acpi/battery/BAT1/state' 15 | batteryinfo = open(filename).read() 16 | 17 | m = re.search('remaining capacity:\s+(\d+)', batteryinfo) 18 | 19 | n = re.search('charging state:\s+(\w+)', batteryinfo) 20 | charge_status = n.group(1) 21 | 22 | charging = True 23 | if charge_status == 'discharging': 24 | charging = False 25 | 26 | return int(m.group(1)), charging 27 | 28 | if __name__ == '__main__': 29 | pynotify.init('Battery Daemon') 30 | notified = False 31 | while True: 32 | battery, charging = get_battery_status() 33 | if not charging and battery < limit: 34 | if not notified: 35 | notified = True 36 | n = pynotify.Notification('Battery Daemon', 'Your battery is mad low bro. You should hibernate.') 37 | n.set_urgency(pynotify.URGENCY_CRITICAL) 38 | n.show() 39 | else: 40 | notified = False 41 | 42 | print battery, charging 43 | time.sleep(sleeptime) 44 | --------------------------------------------------------------------------------