import operator
import subprocess


def to_irc_lower(s):
  return s.casefold()


def make_flag_pair(mutator):
  return (lambda o, param=None: mutator(o, True),
          lambda o, param=None: mutator(o, False))


def is_channel_name(name):
  return name and name[0] == "#"


def show_modes(modes):
  flags = []
  args = []

  for k, v in sorted(modes.items(), key=operator.itemgetter(0)):
    flags.append(k)

    if v is not True:
      args.append(v)

  return "+" + "".join(flags), args


def get_version():
  try:
    hash = subprocess.check_output([
        "git", "rev-parse", "--short", "HEAD"]).strip().decode("utf-8")
    is_dirty = subprocess.check_output(["git", "status", "--porcelain"]) != ""
  except subprocess.CalledProcessError:
    return "HEAD"
  else:
    return hash + ("-dirty" if is_dirty else "")

import operator
import subprocess


def to_irc_lower(s):
  return s.casefold()


def make_flag_pair(mutator):
  return (lambda o, param=None: mutator(o, True),
          lambda o, param=None: mutator(o, False))


def is_channel_name(name):
  return name and name[0] == "#"


def show_modes(modes):
  flags = []
  args = []

  for k, v in sorted(modes.items(), key=operator.itemgetter(0)):
    flags.append(k)

    if v is not True:
      args.append(v)

  return "+" + "".join(flags), args


def get_version():
  try:
    hash = subprocess.check_output([
        "git", "rev-parse", "--short", "HEAD"]).strip().decode("utf-8")
    is_dirty = bool(subprocess.check_output(["git", "status", "--porcelain"]))
  except subprocess.CalledProcessError:
    return "HEAD"
  else:
    return hash + ("-dirty" if is_dirty else "")

fix version check