Ack.

Surest way to find out where your googling skills are weakest is to post 
something to a public mailing list. :)

That said, I still think there would be some utility in being able to check 
the line-endings on the system.  But I wouldn't be prepared to argue 
strongly for it.

oc


On Wednesday, January 4, 2017 at 12:58:28 PM UTC-5, José Valim wrote:
>
> For the particular problem of finding an executable, can't you use 
> System.find_executable/1?
>
>
>
> *José Valim*
> www.plataformatec.com.br
> Skype: jv.ptec
> Founder and Director of R&D
>
> On Wed, Jan 4, 2017 at 6:22 PM, Onorio Catenacci <[email protected] 
> <javascript:>> wrote:
>
>> Hi all,
>>
>> Recently I've been working on some utility Elixir scripts. One of the 
>> scripts I was working on was a "Work In Progress" script for checking my 
>> current progress into git.  The thing that I ran across that was 
>> interesting to me is (I hope) demonstrated by the code below:
>>
>> # We may want to memoize this at some point in the future but it hardly 
>> seems worth the extra complication right now.
>>   defp find_exe(command_to_find, default_command) do
>>     case {command, _} = System.cmd 
>> get_correct_search_command(),[command_to_find] do
>>       {_,1} -> default_command
>>       {_,0} -> String.trim(command,get_correct_line_ending())
>>     end
>>   end
>>
>>   defp get_correct_line_ending() do
>>     case {_osfamily, _} = :os.type() do
>>       {:unix,_} -> "\n"
>>       {:win32,_} -> "\r\n"
>>       {:ose,_} -> "\n"
>>       {_,_} -> "\n" # This should not ever get hit
>>     end
>>   end
>>
>>   defp get_correct_search_command() do
>>     case {_osfamily, _} = :os.type() do
>>       {os,_} when os in [:unix,:ose] -> "which"
>>       {:win32,_} -> "where"
>>     end
>>   end
>>
>> I'm trying to find the git command on the path.  As far as I know on 
>> Linux and OSX that's "which" and on Windows it's "where".  But the thing is 
>> "where" returns the string with a "\r\n" at the end.  I can trim this but, 
>> of course, I need to figure out the right line ending for the OS I'm 
>> currently on.  I confess I didn't try this on Linux or Mac to see if 
>> "which" behaves the same or not but I can see some utility to knowing which 
>> line-ending is present on your current OS as part of the standard System 
>> module. 
>>
>> I don't think there's anything in the System module to simply get the 
>> correct line-ending for the current OS--at least I couldn't find it.  I 
>> could swear that Jose mentioned to me once that there's something 
>> internally to get the correct line ending for the current OS.  Could we 
>> maybe expose the current correct line ending?  Maybe 
>> System.os_specific_line_ending or something of that sort?  As I say, I 
>> recall Jose mentioning something to me about this in the past and if we've 
>> already discussed it and decided against it, I apologize.  I didn't turn up 
>> anything on a search of the archives. 
>>
>> Does this seem like a good idea? Thoughts? Criticisms? :)
>>
>> oc
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "elixir-lang-core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/elixir-lang-core/6cc54b36-3215-46f3-8d77-73e6cd50604c%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/elixir-lang-core/6cc54b36-3215-46f3-8d77-73e6cd50604c%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/53339714-625c-45bd-9325-aacf70489321%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to