I've got a CLI utility for copying files, basically.
{-# LANGUAGE OverloadedStrings #-}
...
import Turtle
...
{- Command line parser -}
-- | Represents command line options.
data Settings = Settings
{ sVerbose :: Bool
...
, sSrc :: FilePath
, sDst :: FilePath
}
...
Tracing code:
...
-- | Extracts String From FilePath (unsafe and unofficial).
-- No double quotes allowed in paths.
strp :: FilePath -> String
strp path =
let parts = splitOn "\"" (show path)
in parts !! 1
...
putStrLn "Наблюдаем юникод"
putStrLn $ strp (sSrc args)
putStrLn $ strp src
...
Working code:
...
src <- realpath (sSrc args)
...
Console input for sSrc
is actually .
Console output:
Наблюдаем юникод
./
/home/alexey/common/Downloads/UpDown/Books/Audio/_Nonfiction_/Moral Combat \8211 Good and Evil in World War II [Unabridged]/
1/26 /home/alexey/dir-dst/Moral Combat \\8211 Good and Evil in World War II [Unabridged]/01-Moral Combat \\8211 Part 01.mp3
\8211
is some kind of dash. The escaped path is produced by realpath
right out of the .
. I don't know the reason why. Is it the particular i/o library? Is it compiler options? The only thing so far that wouldn't escape unicode characters is putStrLn
.
I want the original path intact.
UPD:
Make it easy to extract a file path as Text from a FilePath
The hack now looks prettier:
import qualified Filesystem.Path.CurrentOS as FPS
import Data.Either.Extra
...
-- | Extracts String From FilePath
-- (good until deprecated system-filepath removed).
strp :: FilePath -> String
strp path = T.unpack $ fromRight "" (FPS.toText path)
And it works, for the time being. Still, I like the idea of mandatory escaping not at all. show
and print
are very helpful generally, and often rendered useless by escaping. No way to turn this off?