pmenu

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

pmenu (1075B)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash

# Program list
programs_name=$(pactl list sink-inputs | grep -Po 'binary = "\K[^"]*')

programs_index=$(pactl list sink-inputs | grep -Po '(?<=Sink Input #).*')

# Sink list
sinks_name=$(pactl list sinks | grep -Po 'Description: \K.*')

sinks_index=$(pactl list sinks | grep -Po '(?<=Sink #).*')

# Format values n' what not
IFS=$'\n' p_n_db=($programs_name)
p_n_size=${#p_n_db[@]}+1

IFS=$'\n' p_i_db=($programs_index)
p_i_count=${#p_i_db[@]}

IFS=$'\n' s_n_db=($sinks_name)
s_n_size=${#s_n_db[@]}+1

IFS=$'\n' s_i_db=($sinks_index)
s_i_count=${#s_i_db[@]}


ret_prog=$(printf '%s' "$programs_name" | dmenu -l $p_n_size)

ret_sink=$(printf '%s' "$sinks_name" | dmenu -l $s_n_size)

# Get indexes of ret_prog and ret_sink in *_name_db
for (( i = 0; i < ${#p_n_db[@]}; i++ )); do
	if [ "${p_n_db[$i]}" = "${ret_prog}" ]; then
		index_prog=$i;
	fi
done

for (( i = 0; i < ${#s_n_db[@]}; i++ )); do
	if [ "${s_n_db[$i]}" = "${ret_sink}" ]; then
		index_sink=$i;
	fi
done

# Execute command
ret=$(pactl move-sink-input ${p_i_db[$index_prog]} ${s_i_db[$index_sink]})