import math


def format_hash(hash_str: str, hash_len: int, hash_seg_len: int, hash_sep: str) -> str:
    """
    Format a hash string: keep only hash_len chars from it, and break it up into
    segments of len hash_seg_len, using the hash_sep as separator. Ex:
    >>> format_hash('abcdef1232567890', 8, 2, '-')
    ab-cd-ef-12
    """
    hash_str = hash_str[:hash_len]
    if hash_seg_len >= hash_len:
        return hash_str
    num_segs = math.ceil(len(hash_str) / hash_seg_len)
    return hash_sep.join(hash_str[hash_seg_len * i: (hash_seg_len * i + hash_seg_len)]
                         for i in range(num_segs))