annotate .plrc @ 12:4bf4943f93a4

Forgot to switch branches in ClioPatria repo - now added in ~/etc/setup_as_dml.sh
author samer
date Mon, 19 Jan 2015 14:23:19 +0000
parents 3255717f4e6b
children d75099ce5f13
rev   line source
samer@2 1 :- op(200,fy,@).
samer@2 2
samer@2 3 persistent_history(H) :-
samer@2 4 prolog_history(disable),
samer@2 5 (exists_file(H) -> rl_read_history(H); true),
samer@2 6 current_prolog_flag(argv,ARGV),
samer@2 7 get_time(Now),
samer@2 8 format_time(string(Time),'%+',Now),
samer@2 9 format(atom(Header),'% Start: ~w - argv=~w.\n',[Time,ARGV]),
samer@2 10 rl_add_history(Header),
samer@2 11 at_halt(rl_write_history(H)).
samer@2 12
samer@2 13 colour_terminal :-
samer@2 14 stream_property(user_output, tty(true)),
samer@2 15 getenv('TERM',Term),
samer@2 16 member(Term,[xterm,screen,'screen-256color','xterm-256color','xterm-color']).
samer@2 17
samer@2 18 :- dynamic http_proxy/3.
samer@2 19
samer@2 20 get_http_proxy(Host,Port,basic(User,Pwd)) :-
samer@2 21 getenv(use_proxy,yes),
samer@2 22 getenv(http_proxy,Proxy),
samer@2 23 % proxy looks like http://User:Password@Host:Port
samer@2 24 atom_concat('http://',Proxy1,Proxy), % strip off protocol
samer@2 25 split_atom(Proxy1,Auth,'@',HostPort),
samer@2 26 split_atom(Auth,User,':',Pwd),
samer@2 27 split_atom(HostPort,Host,':',APort),
samer@2 28 atom_number(APort,Port).
samer@2 29
samer@2 30 split_atom(Atom,Pre,Mid,Post) :-
samer@2 31 sub_atom(Atom,LPre,_,LPost,Mid),
samer@2 32 sub_atom(Atom,0,LPre,_,Pre),
samer@2 33 sub_atom(Atom,_,LPost,0,Post).
samer@2 34
samer@2 35 internal_host(localhost).
samer@2 36 internal_host(Host) :- sub_atom(Host,_,_,0,'bl.uk').
samer@2 37
samer@2 38 :- multifile http:open_options/2.
samer@2 39 http:open_options(Parts,[proxy(Host,Port),proxy_authorization(Auth)|Opts]) :-
samer@2 40 http_proxy(Host,Port,Auth),
samer@2 41 option(host(Target),Parts),
samer@2 42 \+internal_host(Target),
samer@2 43 debug(proxy,'Using HTTP proxy ~w:~w for ~w',[Host,Port,Target]),
samer@2 44 debug(proxy,'Parts: ~w',[Parts]),
samer@2 45 ( option(scheme(https),Parts)
samer@2 46 -> debug(proxy,'Using HTTPS',[]),
samer@2 47 Opts=[cert_verify_hook(verify_certificate)]
samer@2 48 ; Opts=[]
samer@2 49 ).
samer@2 50
samer@2 51 verify_certificate(_,_,_,_,_) :- format(user_error,'Accepting certificate\n',[]).
samer@2 52
samer@2 53 :- %persistent_history('.swipl_history'),
samer@2 54 (colour_terminal -> load_files(library(ansi_term), [silent(true)]); true),
samer@2 55 set_prolog_flag(prompt_alternatives_on, determinism),
samer@2 56 set_prolog_flag(editor, '$EDITOR'),
samer@2 57 load_files(library(url), [silent(true)]),
samer@2 58 load_files(library(http/http_ssl_plugin), [silent(true)]),
samer@2 59 ( get_http_proxy(Host,Port,Auth)
samer@2 60 -> assert(http_proxy(Host,Port,Auth))
samer@2 61 ; true
samer@2 62 ).
samer@2 63
samer@2 64