Skip to content

Instantly share code, notes, and snippets.

@thymbahutymba
Last active March 19, 2018 21:43
Show Gist options
  • Save thymbahutymba/c1582daa093601460731e5ab7e9f5246 to your computer and use it in GitHub Desktop.
Save thymbahutymba/c1582daa093601460731e5ab7e9f5246 to your computer and use it in GitHub Desktop.
Find which packages require the list of input packages
#!/bin/sh
[ $# -eq 0 ] && echo "./required_by <list packages>" && exit 1
list_required=();
for package in $*; do
to_sort=($(pacman -Qi $package 2> /dev/null | grep Required | cut -c 19-));
for element in ${to_sort[@]}; do
[[ " $* " == *"$element"* ]] && break
[[ " ${list_required[@]} " == *"$element"* ]] && break
list_required+=($element)
done
done
[ ${#list_required[@]} -eq 0 ] && echo "No results found" && exit 1
echo ${list_required[@]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment