Skip to content

Commit

Permalink
✨ Add user::get_groups function
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Ruthardt <[email protected]>
  • Loading branch information
DanielRuthardt committed Jun 20, 2024
1 parent 26edd8a commit af0ecbb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions libs/user/*
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# shellcheck shell=bash

#include user/get_gid
#include user/get_groups
#include user/get_home
#include user/get_shell
#include user/get_uid
27 changes: 27 additions & 0 deletions libs/user/get_groups
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# shellcheck shell=bash

# user::get_groups
# Retrieves the group memberships of a specified user.
#
# Description:
# This function fetches the group memberships of the user specified by the username argument.
# If no username is provided, it defaults to the current user. This is useful for scripts
# that need to manage permissions or access control based on user groups.
#
# Usage:
# user::get_groups <username>
#
# Parameters:
# username - The username whose group memberships are to be retrieved. Optional, defaults to the
# current user.
#
# Outputs:
# The group memberships of the specified or default user.
#
# Example:
# user::get_groups "exampleUser" # Outputs the groups of 'exampleUser'
# user::get_groups # Outputs the groups of the current user
function user::get_groups() {
local username=${1:-${user:-$(whoami)}}
id --groups --name "$username"
}

0 comments on commit af0ecbb

Please sign in to comment.