mirror of
				https://github.com/sharkdp/bat.git
				synced 2025-10-30 22:54:07 +00:00 
			
		
		
		
	Fix #1413 Can't use bat at all! (Error: Use of bat as a pager is disallowed...)
				
					
				
			Fixed by implementing the proposal by sharkdp: * Allow PAGER=bat, but ignore the setting in bat and simply default to less. Unless of course, BAT_PAGER or --pager is used to overwrite the value of PAGER. * Disallow the usage of bat within BAT_PAGER and --pager.
This commit is contained in:
		
				
					committed by
					
						 David Peter
						David Peter
					
				
			
			
				
	
			
			
			
						parent
						
							060b9981b5
						
					
				
				
					commit
					dd0d44bbb3
				
			
							
								
								
									
										18
									
								
								src/pager.rs
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								src/pager.rs
									
									
									
									
									
								
							| @@ -98,10 +98,20 @@ pub(crate) fn get_pager(config_pager: Option<&str>) -> Result<Option<Pager>, Par | ||||
|         Some((bin, args)) => { | ||||
|             let kind = PagerKind::from_bin(bin); | ||||
|  | ||||
|             // 'more' and 'most' do not supports colors; automatically use 'less' instead | ||||
|             // if the problematic pager came from the generic PAGER env var | ||||
|             let no_color_support = kind == PagerKind::More || kind == PagerKind::Most; | ||||
|             let use_less_instead = no_color_support && source == PagerSource::EnvVarPager; | ||||
|             let use_less_instead = match source { | ||||
|                 PagerSource::EnvVarPager => { | ||||
|                     // 'more' and 'most' do not supports colors; automatically use 'less' instead | ||||
|                     // if the problematic pager came from the generic PAGER env var | ||||
|                     let no_color_support = kind == PagerKind::More || kind == PagerKind::Most; | ||||
|  | ||||
|                     // If PAGER=bat, silently use 'less' instead to prevent recursion ... | ||||
|                     let is_self = kind == PagerKind::Bat; | ||||
|  | ||||
|                     no_color_support || is_self | ||||
|                 }, | ||||
|                 // Never silently replace with less if bat-specific means to set a pager is used | ||||
|                 _ => false | ||||
|             } ; | ||||
|  | ||||
|             Ok(Some(if use_less_instead { | ||||
|                 let no_args = vec![]; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user