Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 556276 Details for
Bug 671936
app-eselect/eselect-timezone Improvement
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
The eselect file I wrote
timezone.eselect (text/plain), 5.48 KB, created by
Ethan Kiang
on 2018-11-26 08:49:59 UTC
(
hide
)
Description:
The eselect file I wrote
Filename:
MIME Type:
Creator:
Ethan Kiang
Created:
2018-11-26 08:49:59 UTC
Size:
5.48 KB
patch
obsolete
># Copyright 1999-2018 Gentoo Foundation ># Distributed under the terms of the GNU General Public License v2 > >DESCRIPTION="Manage the timezone via /etc/timezone" >MAINTAINER="Ethan Kiang" > >#### HELPER METHODS #### > ># Takes in directory parameter, ># get list of files and directories >dir_list() { > local f > for f in $1/*; do > # Ignore non timezone files > if [[ ${f} =~ ^[^\.]*$ ]]; then > if [[ -d ${f} ]]; then > echo "$(basename ${f})/" > else > basename ${f} > fi > fi > done >} > >#$1: Directory $2: Expression >index_to_directory() { > local directory=$1 > IFS='-' read index rest <<< $2 > if [[ -n $index ]]; then > local dirlist=($(dir_list $directory)) > local new_dir=$(echo $directory/${dirlist[$(( $index - 1))]} | \ > sed 's/\/$//') > index_to_directory $new_dir $rest > else > echo $directory > fi > IFS=$' \t\n' >} > >get_path() { > local root="${EROOT}/usr/share/zoneinfo" > if [[ $1 =~ ^([0-9]*)(-[0-9]*)*$ ]]; then > index_to_directory $root $1 > else > echo "$root/$1" > fi >} > ># $1 Base root directory ># $2 Relative directory to find expression of ># Helper for directory_to_index >directory_to_index_helper() { > local i root=$1 > IFS='/' read dir rest <<< $2 > local dirlist=( $(dir_list $root) ) > for ((i=0; i<${#dirlist[@]}; i++)); do > local cur_dir=$(echo ${dirlist[i]} |\ > sed 's/\/$//') > if [[ $dir = $cur_dir ]]; then > echo $(($i + 1 )) > if [[ -n $rest ]]; then > directory_to_index_helper "$root/$dir" $rest > fi > break > fi > done > IFS=$' \t\n' >} > >directory_to_index() { > local expr=( $(directory_to_index_helper "${EROOT}/usr/share/zoneinfo" $1) ) > IFS='-'; echo "${expr[*]}"; IFS=$' \t\n' >} > >#### END OF HELPER METHODS #### > >### list action ### >describe_list() { > echo "Show list of available timezones to select from" >} > >describe_list_parameters() { > echo "[target]" >} > >describe_list_options() { > echo "target : Name or index of sub-directory to show" > echo " all : List all available timezone choices" >} > >list_timezones() { > local directory=$1 basedir="${EROOT}/usr/share/zoneinfo" > local targets=( $(dir_list $directory) ) > local relative_directory=$(realpath --relative-base=$basedir $directory) > local current_tz_expr="$(directory_to_index $(<${EROOT}/etc/timezone))" > local dir_index="$(directory_to_index $relative_directory)" > local enum > > if [[ -n $dir_index ]]; then enum="$dir_index-"; fi > > for ((i=0; i < ${#targets[@]}; i++)); do > local item_num="$enum$(expr $i + 1)" > if [[ ${targets[i]} =~ .*/$ ]]; then > targets[i]=$(highlight "${targets[i]}") > fi > > if [[ $current_tz_expr =~ ^${item_num}(-[0-9]*)*$ ]]; then > targets[i]=$(highlight_marker "${targets[i]}") > fi > write_numbered_list_entry "$item_num" "${targets[i]}" > done >} > >list_timezones_all() { > local directory=$1 basedir="${EROOT}/usr/share/zoneinfo" > local targets=( $(dir_list $directory) ) > local relative_directory=$(realpath --relative-base=$basedir $directory) > local current_tz_expr="$(directory_to_index $(<${EROOT}/etc/timezone))" > local dir_index="$(directory_to_index $relative_directory)" > local enum i > > if [[ -n $dir_index ]]; then enum="$dir_index-"; fi > for ((i=0; i < ${#targets[@]}; i++)); do > local item_num="$enum$(expr $i + 1)" > if [[ ${targets[i]} =~ .*/$ ]]; then > list_timezones_all "$directory/${targets[i]}" > else > if [[ $current_tz_expr =~ ^${item_num}(-[0-9]*)*$ ]]; then > targets[i]=$(highlight_marker "${targets[i]}") > fi > local printed_dir > if [[ $relative_directory != '.' ]]; then > printed_dir="$relative_directory/" > fi > write_numbered_list_entry "$item_num" "$printed_dir${targets[i]}" > fi > done >} > > >do_list() { > local basedir="${EROOT}/usr/share/zoneinfo" > local directory=$(get_path $1) > if [[ $1 = "all" ]]; then > list_timezones_all $basedir > else > [[ -d $directory ]] || die -q "Not a directory!" > > write_list_start "Available timezone selections:" > > echo "Directory: $directory" > list_timezones $directory > fi >} > >### show action ### >describe_show() { > echo "Show the currently set timezone" >} > >do_show() { > write_list_start "Current timezone in /etc/timezone:" > if [[ -f ${EROOT}/etc/timezone ]]; then > write_kv_list_entry "$(<${EROOT}/etc/timezone)" "" > else > write_kv_list_entry "(unset)" "" > fi >} > >### set action ### >describe_set() { > echo "Set a new timezone" >} > >describe_set_parameters() { > echo "<target>" >} > >describe_set_options() { > echo "target : Target name or index (from 'list' action)" >} > >do_set() { > local directory=$(get_path $1) basedir="${EROOT}/usr/share/zoneinfo" > [[ -f $directory ]] || die -q "Not a valid timezone!" > tz=$(realpath --relative-base=$basedir $directory) > echo $tz > /etc/timezone || die -q "Could not write to /etc/timezone" > emerge --config sys-libs/timezone-data || die -q "Could not run emerge, is > this a Gentoo system?" >} > > >### Modified methods from eselect overriden > ># Only difference is space $(( 4 - ${#1} )) -> $(( 7 - ${#1} )) ># Overriden since default method cannot handle large numberings > ># write_numbered_list_entry PUBLIC ># Write out a numbered list entry with index $1 and text $2. Args may ># include text highlighting. If -p is passed, use 'plain' highlighting. >write_numbered_list_entry() { > local left=${COLOUR_LIST_LEFT} right=${COLOUR_LIST_RIGHT} > local normal=${COLOUR_NORMAL} > > if [[ $1 == "-p" ]]; then > left=; right=; normal= > shift > fi > > if ! is_output_mode brief; then > echo -n -e " ${left}" > echo -n -e "[$(apply_text_highlights "${left}" "$1")]" > echo -n -e "${normal}" > space $(( 7 - ${#1} )) > fi > > echo -n -e "${right}" > echo -n -e "$(apply_text_highlights "${right}" "$2")" > echo -e "${normal}" >} ># vim: ts=4 sw=4 noet fdm=marker
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 671936
: 556276