You are not logged in.

I'm using this stanza in ~/.profile as a display manager replacement:
case "$(tty)" in
        "/dev/tty1") exec startx;;
        "/dev/tty2") exec startx /usr/bin/bspwm;;
        "/dev/tty3") exec startx /usr/bin/kodi;;
        "/dev/tty4") exec startx /usr/games/steam -bigpicture;;
esacEDIT: that's from my BunsenLabs system, hence the strange steam path 
Last edited by Head_on_a_Stick (2017-01-01 23:24:34)
Jin, Jîyan, Azadî
Offline

OMG! That's so simple and clean. How did I not think of that?
Thanks for sharing 
Last edited by dmerej (2017-01-03 21:23:42)
Responsible Coder, Python Fan, Rust enthusiast
Offline

Wrote a upnp port forwarder. So I can do forward 4001 4002 4003 to open ports and forward -close 4001 4002 4003 to close them
package main
import (
	"flag"
	"log"
	"os"
	"strconv"
	goupnp "github.com/NebulousLabs/go-upnp"
)
func main() {
	close := flag.Bool("close", false, "Close ports")
	flag.Parse()
	f, err := goupnp.Discover()
	if err != nil {
		log.Println(err)
		return
	}
	for _, v := range os.Args[1:] {
		if v == "-close" {
			continue
		}
		i, err := strconv.Atoi(v)
		if err != nil {
			log.Println(err)
			continue
		}
		if *close {
			if err := f.Clear(uint16(i)); err != nil {
				log.Println(err)
			}
		} else {
			if err := f.Forward(uint16(i), "go forwarder"); err != nil {
				log.Println(err)
			}
		}
	}
}Offline

This one is very tiny, but handy, I have bound this script to "windowskey+o"
lariza $( echo $( xclip -o )) #before coffee
 lariza "$( xclip -o )" Just select the url, and press "win+o" it openes in lariza.
Last edited by Docbroke (2017-01-07 06:52:56)
Arch is home!
https://github.com/Docbroke
Offline

What's with the echo? That's completely redundant:
lariza "$(xclip -o)"FWIW, with qutbrowser, I just need this in keys.conf:
open -t {primary}
    pThen I can just press p to open a tab to whatever was selected - if it wasn't a url the word or phrase will be looked up in my default search engine.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline

looks like I missed morning coffee today.
You need qutebrowser open for using your shortcut, and it is like you select url open qutebrowser or go to the open window and press p.
For search I use my rofi/dmenu bsed script bound to shift+F11. So it is like "hold shift key and press F11 and then press insert" (this opens rofi and  PRIMARY is copied to input)
EDIT: and tabs are managed by i3, so I don't need tabs support in browser, so when I was using qutebrowser I had "tabs are windows" option in my config file.
Last edited by Docbroke (2017-01-07 05:36:07)
Arch is home!
https://github.com/Docbroke
Offline

this two scripts helps to mount/unmout android filesystem through mtp. It depends on simple-mtpfs (commandline utility from aur)
This one is used to mount all android phones connected through mtp
sharad ~ > cat bin/phone
#!/bin/bash
[[ -d ~/mount ]] || mkdir ~/mount
cd ~/mount
for d in $(simple-mtpfs --list-devices | awk '{ print $1 }')
    do [[ -d $d ]] || mkdir "$d"
    simple-mtpfs --device $d $d
donethis one is used to unmount all, and clean the mount directory
sharad ~ > cat bin/unphone
#!/bin/bash
shopt -s lastpipe 
cd ~/mount
echo * | read dir 
for i in $dir
    do fusermount -u $i
done
rmdir ~/mount/*Last edited by Docbroke (2017-01-09 16:42:17)
Arch is home!
https://github.com/Docbroke
Offline
#! /usr/bin/env bash
#Script for simple-mtpfs
PS3="
Select an option.:  "
#mount directory
dir="$HOME/usb"
					
while :; do
  clear
  options="Quit List_Device Mount Umount"
    select opt in $options; do
      case $opt in
        Quit) clear; exit
        ;;
        List_Device) simple-mtpfs --list-devices
        ;;
            
        Mount) simple-mtpfs "$dir"; echo "Mounted to "$dir"" 
        ;;
        Umount) fusermount -u "$dir"; echo "Unmounted" 
        ;;
      esac
    done
doneOffline

@teckk, I haven't tested your script but I guess it won't mount >1 android devices. I still need to find out how to mount selected device when there are >1 devices are connected throught mtp.
Arch is home!
https://github.com/Docbroke
Offline
Oh ok,
simple-mtpfs -l
1: SamsungGalaxy models (MTP)
2: HTCAndroid Device ID2 (Zopo, HD2...)simple-mtpfs --device 1 ~/usb1ls ~/usb1
0                      ServeStream
Alarms                 SpeedSoftware
Android              
BSPlayer1.17.170.apk   brouter
Download........simple-mtpfs --device 2 ~/usb2ls ~/usb2
Alarms   Download    Movies   Pictures   Ringtones    obb
Android  'FM Recording'  Music........mount
....
simple-mtpfs on /home/me/usb1 type fuse.simple-mtpfs (rw,nosuid,nodev,relatime,user_id=1000,group_id=100)
simple-mtpfs on /home/me/usb2 type fuse.simple-mtpfs (rw,nosuid,nodev,relatime,user_id=1000,group_id=100)fusermount -u ~/usb1 ~/usb2 or bothOffline

well I guess you misunderstood, what I was saying is that your script mounts single device, my script posted above mounts all the connected devices, but none of the script allows selecting 1/2 devices from all the connected devices. I already know how to use simple-tmpfs from commandline.
Arch is home!
https://github.com/Docbroke
Offline

touchpad on/off with xinput
#!/bin/bash
[[ $(xinput list-props 12 | awk '/Device Enabled/ { print $4 }') == 0 ]] && (xinput enable 12 && notify-send "touchpad enabled") || (xinput disable 12 && notify-send "touchpad disabled")Note: "12" is device id for touchpad in my laptop
Arch is home!
https://github.com/Docbroke
Offline
You can also use a name instead of an id. I suspect that would be less prone to change. And why cram the whole thing into a single line? How about
#!/bin/bash
# name or id that might change in the future
touchpad=12
if [[ $(xinput list-props "$touchpad" | awk '/Device Enabled/ { print $4 }') == 0 ]]; then
  action=enable
else
  action=disable
fi
xinput $action "$touchpad" && notify-send "touchpad ${action}d"Offline

You can also use a name instead of an id. I suspect that would be less prone to change. And why cram the whole thing into a single line? How about
#!/bin/bash # name or id that might change in the future touchpad=12 if [[ $(xinput list-props "$touchpad" | awk '/Device Enabled/ { print $4 }') == 0 ]]; then action=enable else action=disable fi xinput $action "$touchpad" && notify-send "touchpad ${action}d"
Now I propose putting the final line into a function instead, so the next poster can finally sit down a while and patch bash with an OO component.
Offline

as you wish
#!/bin/bash
#xinput device id for touchpad
touchpad=12
# enable touchpad
ON() {
xinput enable $touchpad && notify-send "touchpad enabled"
}
# disable touchpad
OFF() {
xinput disable $touchpad && notify-send "touchpad disabled"
}
# get status of touchpad
status=$(xinput list-props $touchpad | awk '/Device Enabled/ { print $4 }')
# toggle touchpad status
[[ $status == 0 ]] && ON || OFFLast edited by Docbroke (2017-01-19 09:55:39)
Arch is home!
https://github.com/Docbroke
Offline

Bash does not have a ternary operator, so "&& foo || bar" will have unpredictable results. For example, if "ON" returns false for some reason, "OFF" would still be run.
{ echo 1; true; } && { echo 2; false; } || { echo 3; }                                                                     
1
2
3P.S. That said, please don't post another copy with those changes, we all know what it looks like by now...
Last edited by Alad (2017-01-19 16:42:16)
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline

This has come up before - and using that pseudo-ternary operator is perfectly appropriate in cases like these. If the first conditional is false, the third command will run. The only problem is if the first conditional is true and the second command fails, then the third command will also run. But that will have no side-effect here. If the second command fails, the intended behavior of turning it ON has already failed and it is currently OFF, thus running another command to try to turn it OFF will have no effect.
The logic of the statment is "If it's on, turn it off" and "If it's off, turn it on (and if turning it on fails, go ahead and try to turn it off again)."
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline

Well, you could equally say that there's no need to quote variables because "they won't have white space in them". In the end, you add an unexpected factor to your code which might bite you later. If you really feel like keeping everything on one line, you can seperate if/then with semi-colons.
if foo; then bar; else baz; fiLast edited by Alad (2017-01-19 16:54:54)
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline

No, because variables are by definition variable. They could include anything at some later point. This is not self modifying code - we know a priori what it includes.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline

Bash does not have a ternary operator
Awk does.
Offline

No, because variables are by definition variable. They could include anything at some later point. This is not self modifying code - we know a priori what it includes.
That was just an example. The point is that I wouldn't want to spend extra brain cycles into figuring out if some side effect might or might not manifest, or be relevant in a particular scenario. Especially later on when I completely forgot what my code does.
edit: looks like there were some edits in the meanwhile... I'll pass on painting the bikeshed further.
Last edited by Alad (2017-01-19 17:03:48)
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline

Continuing on the thread, list all optional dependencies that are not installed:
#!/bin/bash
join -v2 -o2.2,2.1 <(expac -Q '%n' | sort) <(expac -Qv '%n\t%o' -l '\t' | awk '$2 !~ /None/ { 
	for(i = 2; i <= NF; ++i) printf("%s\t%s\n", $i, $1) | "sort -k1,1"
}') | sort | column -tMods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline

how about making this readable (less crammed)
Arch is home!
https://github.com/Docbroke
Offline

k
#!/bin/bash
pair_fields() {
	awk '$2 !~ /None/ { 
		for(i = 2; i <= NF; ++i) {
			printf("%s\t%s\n", $i, $1)
		}
	}'
}
join -v2 -o2.2,2.1 <(expac -Q '%n\n%S' -l '\n' | sort) \
	<(expac -Qv '%n\t%o' -l '\t' | pair_fields | sort -k1,1) | sort | column -tLast edited by Alad (2017-01-20 15:25:29)
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline

Note that piping within awk is generally slower than piping it's output. I've confirmed that in this case. Also piping outside awk seems far more readable to me.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline