You are not logged in.
In the spirit of reinventing the wheel, and doing it badly... I dumped all AUR helpers last year and the one piece of functionality I was missing was searching for packages (other than using surfraw, which is fine). So I use this. Let the witchburning begin!
#!/usr/bin/env bash
# Search for packages in repos and AUR
package=$1
url='https://aur.archlinux.org/rpc/?v=5&type=search&by=name&arg='
aurfile='/tmp/aursearch'
pacman -Ss "^${package}$"
status=$?
if (( "$status" != 0 )); then
printf "%s\n" "Not in repos, searching AUR..."
trap "rm '${aurfile}'" EXIT INT TERM
curl -s "${url}$1" -o "$aurfile"
awk '{gsub(/"/,""); printf "• %s\n", $0}' \
<(jshon -e results -a -e Name < "$aurfile")
fi
Offline
I dumped all AUR helpers last year and the one piece of functionality I was missing was searching for packages (other than using surfraw, which is fine). So I use this. Let the witchburning begin!
Okay, let me start.
"Hey, not only do you use AUR helpers, you're the author of one!"
Managing AUR repos The Right Way -- aurpublish (now a standalone tool)
Offline
The only way AUR helpers could be compared to wheels would be to compare them to wheels on a boat.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
The only way AUR helpers could be compared to wheels would be to compare them to wheels on a boat.
Sure, caterpillars work better, and here
it's not an advertisement, it's pure ecological delirium !
Last edited by waitnsea (2020-01-06 09:43:25)
Offline
The only way AUR helpers could be compared to wheels would be to compare them to wheels on a boat.
Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD
Making lemonade from lemons since 2015.
Online
Trilby wrote:The only way AUR helpers could be compared to wheels would be to compare them to wheels on a boat.
It's funny, because AUR helpers actually (mostly) are outdated technology with low efficency.
Inofficial first vice president of the Rust Evangelism Strike Force
Offline
And most of them are also steaming piles of ship!
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I find AUR helpers immensely useful. You can search the AUR, show infos about packages and even be informed about updates with a few quick commands... Then you feed that information to your own scripts and call it a day.
The buildorder command of auracle is really nice.
Offline
From what I've seen, people outright claiming there is no use for AUR helpers have a very limited amount of AUR packages. When you have* more than say, 100 AUR packages, some automation is in order.
To get back to the topic at hand, jq might be worth looking into for the script in #3301.
* "have" can both mean "use" and "maintain". I've certainly seen people maintain more than 300 AUR packages. An AUR helper can just as well assist with maintanance tasks.
Last edited by Alad (2020-01-15 01:04:20)
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline
To get back to the topic at hand, jq might be worth looking into for the script in #3301.
How so? I have always used jshon because it was community contribution. What advantages are there to jq that would make it a worthwhile change?
Offline
Mostly that it would reduce your script to 1-2 lines? E.g there's no need to remove quotes, because of the -r flag.
Last edited by Alad (2020-01-15 02:32:16)
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline
@jasonwryan, I have a few questions about your script #3301
Why do you use curly braces in the trap?
With pacman you search for exact results, why didn't you set it for the AUR search also, any specific reason?
You set variable 'package=$1', the curl command uses '$1', why? Thanks.
Offline
That was an earlier iteration. The current version also searches AUR.
The curly braces are for legibility, and the variable package was setting up for the larger script (I pasted it here for feedback before going further in case I screwed something obvious up)
Offline
Yes clear. I have already used the one from #3301 works nice and it gave me a clear picture how to use the AUR API
I have created a script with the help of yours to update all my AUR packages trough the API, if I think it's ready to publish I will.
I will have a look at the new one you published tomorrow, thanks.
Offline
I have created a script with the help of yours to update all my AUR packages trough the API, if I think it's ready to publish I will.
No! More AUR helpers! See what you've done, triangle thingy!
Last edited by Alad (2020-01-24 10:39:29)
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline
Nice script @jasonwryan, the one on 'shiv'. Though I personally like the pacman search more because it can give you colored output which gives a better separation in my script and shows if the package is already installed, but I think that's personal;)
I adapted the jshon check also.
Here is a first draft based on #3301
#!/bin/bash
# shellcheck disable=2162
#set -x
# AUR helper that leaves you in control
#exclude file, don't search for this package, one package(name only) per line
exclude="$HOME"/bin/exclude/aur-update-excl
buildir="$HOME"/build
#Don't touch the URL's or variables below only if you must
url1='https://aur.archlinux.org/rpc/?v=5&type=search&by=name&arg=' #search api
url2='https://aur.archlinux.org/rpc/?v=5&type=info&arg[]=' #info api
url3='https://aur.archlinux.org/cgit/aur.git/snapshot/' #get package
package=$2
aurfile='/tmp/aurfile'
result='/tmp/result'
trap 'rm -f "$aurfile" "$result"' EXIT INT TERM
type jshon > /dev/null 2>&1 || {
printf "%s\n" "No jshon, bailing...";
exit 1;
}
_reposearch() {
pacman -Ss "^${package}$"
status=$?
if [ "$status" != 0 ]; then
echo "• Not in repos, searching AUR..."
printf "\n" && _aursearch
elif [ "$status" = 0 ]; then
printf "\n" && read -p "• Search AUR too? Y or N : " aur
printf "\n" && [[ "$aur" =~ ([Yy]) ]] && _aursearch || exit
fi
}
_aursearch() {
curl -s "${url1}$package" -o "$aurfile"
mapfile -t aur < <(jshon -e results -a -e Name -u < "$aurfile")
[ ${#aur[@]} -eq 0 ] && printf "• Also not in AUR" && unset aur && exit
printf "%s\n" "• Exit or download one of the AUR result/s"
select name in "${aur[@]}" exit; do
case $name in
exit) unset aur && exit;;
*) printf "%s\n" "$name" > "$result"; printf "\n"; break;;
esac
done
[ -n "$result" ] && unset aur && _get || exit
}
#_checkupd() {
# aurprog=/tmp/aurprog
# aurinfo=/tmp/aurinfo
# aurver=/tmp/aurver
# localver=/tmp/localver
# trap 'rm "$aurinfo" "$aurprog" "$aurver" "$localver"' EXIT INT TERM
# if [ -e "$exclude" ]; then
# pacman -Qm > "$aurprog"
# while read -r excl; do
# sed -i "/$excl/d" "$aurprog"
# done < "$exclude"
# else
# pacman -Qm > "$aurprog"
# fi
# while read -r prog version; do
# echo "$version" > "$localver"
# curl -s "${url2}$prog" -o "$aurinfo"
# jshon -e results -a -e Version -u < "$aurinfo" > "$aurver"
# [ "$( diff "$localver" "$aurver" )" != '' ] &&
# printf "%s\n" "• Update for $prog New version is $(<"$aurver")" && _get
# done < "$aurprog"
#}
_get() {
[ -e "$result" ] && prog="$(<"$result")"
[ "$1" = -g ] && prog="$package"
[ -d "$buildir/$prog" ] &&
mv "$buildir/$prog" "$buildir/${prog}.bak"
curl -sL "${url3}${prog}.tar.gz" -o "$buildir/${prog}.tar.gz"
tar zxvf "$buildir/${prog}.tar.gz" -C "$buildir" && rm "$buildir/${prog}.tar.gz"
printf "%s\n" "• Downloaded $prog & extracted to $buildir/$prog"
}
_pass() {
[ "$1" = -r ] && _reposearch
[ "$1" = -a ] && _aursearch
[ "$1" = -g ] && _get "$@"
# [ "$1" = -u ] && _checkupd
[ "$1" = "" ]
[ -z "$1" ] && printf "%s\\n" "Options: [ -r <package-name> #search package in official repo or/and in AUR ]
[ -a <package-name> #search if package excist in AUR ]
[ -u #check for AUR updates ]
[ -g <package-name> #get AUR package ]"
}
_pass "$@"
exit 0
edit: the exclude file only works for the update part, not the search..;)
made small clean changes, no need for awk at all, 'u - unstring' is enough for this script
edit2: for now I have disabled the check for updates, because not all git packages update their PKGBUILD
There are packages which are good like 'profile-sync-daemon' but a few are not like 'archiso-git'
It would be nice if pkgver was updated to the correct version;) then for scripts like this one you don't have to invent the wheel...
Last edited by qinohe (2020-01-27 17:08:09)
Offline
Switching between two languages is straightforward
But i wanted to switch between 3 languages and display the status
#!/bin/bash
languages=(us il ru)
timeout=1s
file="/tmp/${USER}_LANG"
[ "$file" ] && [ ! -f "$file" ] && touch "$file" && chmod 600 "$file"
while IFS=, read -ra arr; do
current="${arr[0]:=${languages[0]}}" last="${arr[1]:=${languages[1]}}"
done < <( setxkbmap -query | sed -En '/layout/{s/.* //p}' )
setLang() {
setxkbmap "$1,$last"
[ "$file" ] && echo "[${1}]:${last}" > "$file"
"$0" rest &
}
if [ "$1" = rest ]; then
sleep "$timeout"
exit 1
fi
if pgrep -fl "${0##*/} rest" || [ "$last" = "$current" ]; then
for L in "${languages[@]}"; do (( a++ ))
if [ "$L" = "$current" ]; then
setLang "${languages[$((a % ${#languages[@]}))]}"
break
fi
done
else
buff=$last last=$current
setLang "$buff"
fi
an example for i3status
read_file lang {
path = /tmp/noel09_LANG
format = "%title: %content "
}
and a tmux example
set -g status-right "#(cat /tmp/noel09_LANG)"
I enjoy bash, i want get better. roast me!
[edit] updated quoting,
Credit for the implementation goes to gradgrind
Haven't found other ways of getting the active keyboard layout.
[edit2] Is it over-complicated yet?
[edit3] down to ~35 lines from ~80
Last edited by neol09 (2020-02-17 04:51:23)
Offline
Only had a quick glance, but quoting isn't right, you do when you shouldn't '~=' and you don't when you should;)
Advice, install shellcheck or shellcheck-static (AUR) which is without Haskell 'bloat' (if you don't need it).
Shellcheck will at least help you spot really bad things. It may be wrong in rare occasions.
The script masters here may have more good advices..
Welcome to arch
Offline
I've used shellcheck in the past but I've never heard about shellcheck-static! sounds lovely.
will update the post implementing all of it's adivce
Thanks for the warm welcome!
Offline
[edit2] Is it over-complicated yet?
Well, kinda yes for something that can be done with 'setxkbmap us/il/ru'
It does work though. I haven't got a use for it anyway but sure you can simplify it.
Hobby away I'm sure you figure it out.
edit: at least one example;)
setxkbmap -query -symbols | awk '/layout/{print $2}'
oops, of course I meant
setxkbmap -query |awk '/layout/{print $2}'
Last edited by qinohe (2020-02-16 18:52:48)
Offline
up until recently i was using
setxkbmap -layout us,il,ru -option grp:lalt_lshift_toggle
The problem with that is that you can't get the active layout.
cause setxkbmap -query returns the whole array of languages in it's original order. so some form of scripting was necessary either way
I realize the simplest way of handling this would be something like
case setxkbmap -query | sed -n '/layout/{s/.* //p}' in
us) setxkbmap il ;;
il) setxkbmap ru ;;
ru|*) setxkbmap us ;;
esac
infact that's what i started with trying to change two aspects of it
1) i wanted to declare languages once, hardcoding as little as possible
2) i wanted a wanted a way to switch back to the last active layout instead of having to cycle through all of them
The cache file was originally supposed to hold a current & last language aswell as a timestamp, the timestamp i've already gotten rid by taking a rest
I suppose i could get rid of the cache entirely if i were to pass the second language to setxkbmap aswell
setxkbmap "$1,$last"
But that would leave me with having to setxkbmap -query from every source i'd like to display this info, which is a bit troublesome for me.
I've polished (or made a mess of-) it some more, updating OP. really appreciate your feedback \o/
It is /pretty much/ done tho
Offline
It's not that I don't like your script, but it 's like using a Caterpillar to get a sugar cube in your tea
I was thinking something like
lang() { [ -n "$1" ] && setxkbmap "$1" || setxkbmap -query | awk '/layout/{print $2}' }
Put that in your shell rc, use 'lang' to find out which lang is used & use 'lang il/ru/us' to change it...
Offline
I'll have a cup of coffee, thank you
lang() { [ -n "$1" ] && setxkbmap "$1" || setxkbmap -query | awk '/layout/{print $2}' }
There's an inherit flaw with this approach I believe, Doesn't setxkbmap take arguments exclusively in english?
But it's true that script is too specific for my scenario to be useful, oh well.
here's a snippet before i shut up, for those evil web-services that accept pictures in textboxes
I'll spare you from the boiler-plating this time
scrot -q 100 -z -s -e 'xclip -sel clip -t $$(file -b --mime-type "$f") $f; rm $f'
Offline
There's an inherit flaw with this approach I believe, Doesn't setxkbmap take arguments exclusively in english?
Right, haven't thought about that, I never use Hebrew or Cyrillic keyboards.
Try to think outside the box, I'm sure can let that one-liner help you, keybinding springs to mind...
Now I shut up too, this isn't a support thread and I don't need to be tapped on the finger...
If you need more open a thread.
BTW. I'll have coffee too..;)
Offline
@neol09, I was editing a dmenu script and thought why not dmenu...
A keyboard switcher in dmenu
#!/bin/sh
[ -f "$XDG_CONFIG_HOME"/dmenu/dmenurc ] &&
. "$XDG_CONFIG_HOME"/dmenu/dmenurc || dmindex='dmenu -l 5'
trap clean EXIT HUP INT QUIT TERM
clean() {
unset kbd && exit 0
}
_menu() {
kbl=$(printf "il\nru\nus\nlang" \
| $dmindex -p 'keyboard layout:' -w 240)
}
_menu
if [ "$kbl" = lang ]; then
setxkbmap -query | awk '/layout/{print $2}' \
| $dmindex -p 'current layout:' -w 240
elif [ -n "$kbl" ]; then
setxkbmap "$kbl"
fi
If you don't have a dmenurc here is one:
# RAL 9004 0n RAL 9003 & choice RAL 9007 or reversed.
dmindex='dmenu -i -l 10 -fn DejaVu-Sans-Mono-10 -nb #2e3032 -nf #f4f8f4 -sb #2e3032 -sf #8f8f8c'
#dmindex='dmenu -i -l 10 -fn DejaVu-Sans-Mono-10 -nb #f4f8f4 -nf #2e3032 -sb #8f8f8c -sf #2e3032'
Offline