Skip to content

Instantly share code, notes, and snippets.

@waltarix
Created November 29, 2011 04:00
Show Gist options
  • Save waltarix/1403346 to your computer and use it in GitHub Desktop.
Save waltarix/1403346 to your computer and use it in GitHub Desktop.
zsh: Completion treats filename that is encoded in UTF-8-MAC as UTF-8.
diff --git a/Src/utils.c b/Src/utils.c
index 26e2a5c..04c3783 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -4244,6 +4244,13 @@ mod_export char *
zreaddir(DIR *dir, int ignoredots)
{
struct dirent *de;
+#ifdef HAVE_ICONV
+ static iconv_t conv_ds = (iconv_t)NULL;
+ static char *conv_name = (char *)NULL;
+ char *temp_name;
+ char *temp_name_ptr, *orig_name_ptr;
+ size_t temp_name_len, orig_name_len;
+#endif
do {
de = readdir(dir);
@@ -4252,6 +4259,23 @@ zreaddir(DIR *dir, int ignoredots)
} while(ignoredots && de->d_name[0] == '.' &&
(!de->d_name[1] || (de->d_name[1] == '.' && !de->d_name[2])));
+#ifdef HAVE_ICONV
+ if (!conv_ds)
+ conv_ds = iconv_open("UTF-8", "UTF-8-MAC");
+ if (conv_ds) {
+ orig_name_ptr = de->d_name;
+ orig_name_len = strlen(de->d_name);
+ conv_name = zrealloc(conv_name, orig_name_len+1);
+ temp_name_ptr = conv_name;
+ temp_name_len = orig_name_len;
+ if (iconv(conv_ds,&orig_name_ptr,&orig_name_len,&temp_name_ptr,&temp_name_len) >= 0) {
+ *temp_name_ptr = '\0';
+ temp_name = conv_name;
+ return metafy(temp_name, -1, META_STATIC);
+ }
+ }
+#endif
+
return metafy(de->d_name, -1, META_STATIC);
}
@Jun-T
Copy link

Jun-T commented Jun 5, 2014

Thank you for a useful patch. This has been merged into zsh's main repository:
http://sourceforge.net/p/zsh/code/ci/b3e5284f13162dc6941d5a5c1f2df9772eff2a8c/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment