pomerge() {
    name="$1"
    lang="${2:-cs_CZ.UTF-8}"
    git_root="$(git worktree list --porcelain | awk 'NR == 1 {print $2; exit}')"
    app_po="${git_root}/www/app/translate/gettext/$lang/LC_MESSAGES/$name.po"
    new_po="${git_root}/www/userdata/locale/${name}_new.po"
    [[ -d "$(dirname "$app_po")" ]] || mkdir -p "$(dirname "$app_po")"
    [[ -e "$new_po" ]] || { echo "$new_po does not exist" ; return 1 ;}
    if ! [[ -e "$app_po" ]]
    then
        cp -v "$new_po" "$app_po"
        return
    fi
    tmp="$(mktemp)"
    msgcat --use-first --no-location --no-wrap "$app_po" "$new_po" > "$tmp"
    mv "$tmp" "$app_po"
}

pocompile() {
    name="$1"
    lang="${2:-cs_CZ.UTF-8}"
    git_root="$(git worktree list --porcelain | awk 'NR == 1 {print $2; exit}')"
    app_po="${git_root}/www/app/translate/gettext/$lang/LC_MESSAGES/$name.po"
    [[ -e "$app_po" ]] || { echo "$app_po does not exists"; return 1; }

    msgfmt -o "${app_po%po}mo" "$app_po"
}

# man() {
#     if [[ "$1" = -k ]] || [[ "$1" = '---' ]] ; then
#         command man "$@"        
#     elif [[ -n "$1" ]]; then
#         vim man://$1
#     else
#         echo 'What manual page do you want?'
#         return 1
#     fi
# }

inplace() {
    local file=$1
    shift

    local tmp=$(mktemp)

    cp $file $tmp
    $@ < $tmp > $file
}

refresh() {
    local d=$HOME/.cache/zsh/
    if ! [[ -d $d ]]
    then
        echo "$d is not dir" >&2
        exit 1
    fi
    rm -rf $d/*
    exec zsh
}
