From c6793325d1c1a37766f85ac977ce53a904ac410b Mon Sep 17 00:00:00 2001 From: Joey Riches Date: Wed, 27 Sep 2023 16:29:31 +0100 Subject: [PATCH] common: Initial helpers script to provide common functionality --- common/Scripts/helpers.sh | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 common/Scripts/helpers.sh diff --git a/common/Scripts/helpers.sh b/common/Scripts/helpers.sh new file mode 100755 index 00000000000..aded0d2825c --- /dev/null +++ b/common/Scripts/helpers.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +# Goes to the root directory of the solus packages +# git repository from anywhere on the filesystem. +# This function will only work if this script is sourced +# by your bash shell. +function gotosoluspkgs() { + pushd $(dirname $(readlink "${BASH_SOURCE[0]}"))/../../ +} + +# Goes to the root directory of the git repository +function goroot() { + pushd $(git rev-parse --show-toplevel) +} + +# Push into a package directory +function gotopkg() { + pushd $(git rev-parse --show-toplevel)/packages/*/$1 +} + +# What provides a lib +function whatprovides() { + grep $1 $(git rev-parse --show-toplevel)/packages/*/*/abi_libs +} + +# What uses a lib +function whatuses() { + grep $1 $(git rev-parse --show-toplevel)/packages/*/*/abi_used_libs +} + + +# Bash completions +_gotopkg() +{ + + _list=$(ls $(git rev-parse --show-toplevel)/packages/*/) + + local cur prev + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + prev="${COMP_WORDS[COMP_CWORD-1]}" + + if [[ $COMP_CWORD -eq 1 ]] ; then + COMPREPLY=( $(compgen -W "${_list}" -- ${cur}) ) + return 0 + fi +} + +complete -F _gotopkg gotopkg