This is split out of #23 The ideal would be to just use bat's logic, see https://github.com/sharkdp/bat/issues/919#issuecomment-1270995318